Skip to content

Instantly share code, notes, and snippets.

@daBee
Created March 5, 2018 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daBee/0aa73f766b781070d6fea6fe547df40b to your computer and use it in GitHub Desktop.
Save daBee/0aa73f766b781070d6fea6fe547df40b to your computer and use it in GitHub Desktop.
class Pickle
attr_accessor :id, :name, :colour, :status
def initialize()
@name = nil
@colour = 'green'
@status = 'new'
end
def into_me(**formparams)
formparams.each do |k,v|
# puts k, v
# puts "yes - #{ k }" if instance_variables.include?(k.to_sym)
# puts "no - #{ k }" if !instance_variables.include?(k.to_sym)
instance_variable_set(k.to_sym, v) if instance_variables.include?(k.to_sym)
setter = ""
end
end
def showme()
instance_variables.each do |i|
print "#{ i } ("
puts "#{ i.class })"
end
end
end
a = Pickle.new
pp a
puts
puts
newstuff = {:name => 'Peter', :colour => 'red'}
a.into_me(newstuff)
a.showme
pp a
@daBee
Copy link
Author

daBee commented Mar 5, 2018

Output:

#<Pickle:0x00007fcf858b8380 @colour="green", @name=nil, @status="new">

@name (Symbol)
@colour (Symbol)
@status (Symbol)
#<Pickle:0x00007fcf858b8380 @colour="green", @name=nil, @status="new">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment