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
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
id and class are built-in ruby methods that are present on all object instances. Rails uses them in a different manner than the default Ruby implementation. They are undefined so that they can be picked up by the method_missingmethod. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/KJ4aGP2TFHQJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
that makes sense, thanks On Apr 30, 12:41 pm, Tim Shaffer <timshaffe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> id and class are built-in ruby methods that are present on all object > instances. > > Rails uses them in a different manner than the default Ruby implementation. > > They are undefined so that they can be picked up by the method_missingmethod.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.