From: furtive.clown@... Date: 2007-11-13T19:20:02+09:00 Subject: Re: Whats the ruby way of associating metadata with a functi On Nov 13, 4:43 am, Keith Chapman wrote: > > foo.bar = "bar"; > function foo(){ > > } > > foobar.bar = "foobar"; > function foobar(){ > > } > > How can I support something like this? require 'ostruct' class FunctionWithMetaData < OpenStruct def initialize(&block) super @func = block end def call(*args) @func.call(*args) end end foo = FunctionWithMetaData.new { |x| x*10 } foo.bar = "qux" foo.baz = "bop" puts foo.bar # => "qux" puts foo.baz # => "bop" puts foo.call(3) # => 30 fred = FunctionWithMetaData.new { "fred function" } fred.arms = 2 fred.fingers = 10 puts fred.arms # => 2 puts fred.fingers # => 10 puts fred.call # => "fred function"