mrblib/object.rb
# Set an attribute of an object.
# @api private
# @param name [String]
# @param value [Object]
# @return [Boolean] if assignment was possible
Set an attribute of an object.
Set an attribute of an object .
def _attribute__set_attribute(name, value)
    restriction = self.class._attribute__assignment_restriction
    case restriction
    when :unavailable
      false
    when :singleton_method
      begin
        self.define_singleton_method(name) { value }
        if value == nil
          self.singleton_class.send(:undef_method, name)
        end
        true
      rescue TypeError
        self.class._attribute__assignment_restriction = :unavailable
        _attribute__set_attribute(name, value) 
      end
    else 
      begin
        instance_variable_set("@#{name}", value)
        if value == nil
          remove_instance_variable("@#{name}")
        end
        true
      rescue ArgumentError
        self.class._attribute__assignment_restriction = :singleton_method
        _attribute__set_attribute(name, value) 
      end
    end
  end
def _attribute__set_attribute ( name , value ) restriction = self . class . _attribute__assignment_restriction case restriction when :unavailable false when :singleton_method begin self . define_singleton_method ( name ) { value } if value == nil self . singleton_class . send ( :undef_method , name ) end true rescue TypeError self . class . _attribute__assignment_restriction = :unavailable _attribute__set_attribute ( name , value ) end else begin instance_variable_set ( "@#{name}" , value ) if value == nil remove_instance_variable ( "@#{name}" ) end true rescue ArgumentError self . class . _attribute__assignment_restriction = :singleton_method _attribute__set_attribute ( name , value ) end end end
Set an attribute of an object.
Set an attribute of an object .
# we know it is assignable now leave undefined to save memory #retry with new restriction # assume we can use an instance variable # we know it is assignable now remove instance variable to save memory #retry with new restriction
if assignment was possible
if assignment was possible
Boolean
name
<not_specific>
value
<not_specific>
<not_specific>
None
api
None