John Merlino
unread,Apr 30, 2012, 12:18:08 PM4/30/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Talk
I see something like this:
require "ostruct"
class OptionsWrapper < OpenStruct
undef :id, :class
def [](key)
send(key)
end
def []=(key, value)
send("#{key}=", value)
end
def method_missing(method, *args, &block)
return @table.include?(method) ? @table.send(method) : nil if
%w(id class).include?(method.to_s)
@table.respond_to?(method) ? @table.send(method, *args, &block) :
super
end
end
I know OpenStruct is a class part of standard ruby library allowing
you to arbitrarily create methods on an object instance. I know that
undef allows you to set a method to nil. But I dont see why it is
needed in this case.
thanks for response