module DynaStruct::Modifiable

Public Instance Methods

<<(args) click to toggle source
# File lib/dyna_struct/modifiable.rb, line 3
def <<(args)
  add_attributes args if args.kind_of?(Hash)
  self
end
empty?() click to toggle source
# File lib/dyna_struct/modifiable.rb, line 17
def empty?
  instance_variables.empty?
end
remove(*vars) click to toggle source
# File lib/dyna_struct/modifiable.rb, line 8
def remove(*vars)
  result = vars.map do |var|
    remove_singleton_method(var.to_s) if singleton_method_defined?(var.to_s)
    remove_singleton_method("#{var}=") if singleton_method_defined?("#{var}=")
    remove_instance_variable("@#{var}") if instance_variable_defined?("@#{var}")
  end
  result.length == 1 ? result.first : result
end

Private Instance Methods

remove_singleton_method(method_name) click to toggle source
# File lib/dyna_struct/modifiable.rb, line 22
def remove_singleton_method(method_name)
  singleton_class.send(:remove_method, method_name)
end
singleton_method_defined?(method_name) click to toggle source
# File lib/dyna_struct/modifiable.rb, line 26
def singleton_method_defined?(method_name)
  singleton_class.send(:method_defined?, method_name)
end