提交 f1220516 编写于 作者: A Alexey Gaziev
上级 92572241
......@@ -109,7 +109,7 @@ def #{name}?
end
private
def singleton_class?
ancestors.first != self
end
def singleton_class?
ancestors.first != self
end
end
......@@ -20,23 +20,21 @@ def superclass_delegating_accessor(name, options = {})
define_method("#{name}?") { !!send("#{name}") } if options[:instance_reader] != false
end
private
# Take the object being set and store it in a method. This gives us automatic
# inheritance behavior, without having to store the object in an instance
# variable and look up the superclass chain manually.
def _stash_object_in_method(object, method, instance_reader = true)
singleton_class.remove_possible_method(method)
singleton_class.send(:define_method, method) { object }
remove_possible_method(method)
define_method(method) { object } if instance_reader
end
def _superclass_delegating_accessor(name, options = {})
singleton_class.send(:define_method, "#{name}=") do |value|
_stash_object_in_method(value, name, options[:instance_reader] != false)
private
# Take the object being set and store it in a method. This gives us automatic
# inheritance behavior, without having to store the object in an instance
# variable and look up the superclass chain manually.
def _stash_object_in_method(object, method, instance_reader = true)
singleton_class.remove_possible_method(method)
singleton_class.send(:define_method, method) { object }
remove_possible_method(method)
define_method(method) { object } if instance_reader
end
send("#{name}=", nil)
end
def _superclass_delegating_accessor(name, options = {})
singleton_class.send(:define_method, "#{name}=") do |value|
_stash_object_in_method(value, name, options[:instance_reader] != false)
end
send("#{name}=", nil)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册