# Keyword arguments in a block, possible with zero arguments?

**URL:** <https://www.ruby-forum.com/t/keyword-arguments-in-a-block-possible-with-zero-arguments/88674>\
**Category:** Ruby\
**Created:** [March 13, 2007, 1:47pm UTC](https://www.ruby-forum.com/t/keyword-arguments-in-a-block-possible-with-zero-arguments/88674 "2007-03-13T13:47:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 13, 2007, 1:47pm UTC](https://www.ruby-forum.com/t/keyword-arguments-in-a-block-possible-with-zero-arguments/88674/1 "2007-03-13T13:47:16Z")

</div>

Hi

I am trying to create a method dynamically that has keyword arguments.  
The variable properties is a hash like {:text =\> “Text”, :something =\>  
“something”}.

My problem is that I want the method created to be able to take 0 or  
more arguments. I know how to do this with an array, but is it possible  
to do this with an hash and keyword arguments?

I mean to write something else than |options| that makes the method able  
to take 0 arguments as well as more arguments?

# This method is in a class

def self.add\_method(name, &block )  
define\_method(name, &block)  
end

# The method add\_method is called on an instance of the class

instance\_of\_generated\_class.add\_method(methodName) do  
|options|  
options = properties.merge(options)

```
#some code

```

end

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [March 13, 2007, 2:34pm UTC](https://www.ruby-forum.com/t/keyword-arguments-in-a-block-possible-with-zero-arguments/88674/2 "2007-03-13T14:34:16Z")

</div>

On Tue, 13 Mar 2007, Peter Motzfeldt wrote:

> I mean to write something else than |options| that makes the method able  
> options = properties.merge(options)
> 
> #some code  
> end

def self.add\_method name, &block  
define\_method name do |\*argv|  
options = argv.shift || {}  
options = properties.merge(options)

```
 # some code

```

end  
end

regards.

-a
