Created
March 5, 2018 22:35
-
-
Save daBee/0aa73f766b781070d6fea6fe547df40b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
#<Pickle:0x00007fcf858b8380 @colour="green", @name=nil, @status="new">
@name (Symbol)
@colour (Symbol)
@status (Symbol)
#<Pickle:0x00007fcf858b8380 @colour="green", @name=nil, @status="new">