Even though I agress that using the same name for both the local
parameter and a method with the same name might be a bad idea, my code
still works without any problem. If I redefine self using to:
There’s working code, and there’s clear code. The goal is working code
that is clear!
Hmmm…why can you merge() but not directly assign to
individual keys when a hash is frozen?
Duh. Because merge() produces a new hash–it doesn’t change the frozen
hash.
Even though I agress that using the same name for both the local
parameter and a method with the same name might be a bad idea, my code
still works without any problem. If I redefine self using to:
(minor change to last version. I split up the calls to merge, select,
and freeze to its own rows.)
def self.using(options)
Class.new(self) do
puts “Superclass options: #{superclass.options.inspect}”
puts “Options from parameter: #{options}” @options = superclass.options.merge(options) @options.select! { |key, value| superclass.options.has_key?
(key) } @options.freeze
end
end
it clearly shows that options (by itself) refers to the local paramter
and not the class name.