On Nov 13, 4:43 am, Keith Chapman <keithgchap... / gmail.com> 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"