Names for these setting helper methods

T

T. Onoma

Can anyone think of better names for these?

class Object

def instance_from(f, *msgs)
msgs.each { |m| self.instance_variable_set( "@#{m}", f.send(m) ) }
end

def set_from(f, *msgs)
msgs.each { |m| self.send( "#{m=}", f.send(m) ) }
end

end
 
M

Markus

In my code I call the first one (or rather, its analog, which takes a
hash) "Object#absorb" and would probably call the second one something
like "Object#soak_in".

class Object
def exude(*fields=self.instance_variables)
fields.collect_hash { |m| self.instance_variable_get( m ) }
end
def absorb(field_values)
field_values.each_pair { |k,v|
self.instance_variable_set( k,v )
}
end
def soak_in(field_values)
field_values.each.pair { |k,v| self.send( "#@{k}=", v ) }
end
end

WARNING: ABOVE CODE TYPED FROM MEMORY WITH A TODDLER'S HELP

-- MarkusQ
 
T

trans. (T. Onoma)

In my code I call the first one (or rather, its analog, which takes a
hash) "Object#absorb" and would probably call the second one something
like "Object#soak_in".

Hmm... you give me idea!

class Object
def vulcan_mind_meld(field_values)
field_values.each_pair { |k,v|
if k.to_s[0..0] == '@'
self.instance_variable_set( k,v )
else
self.send( "#@{k}=", v ) }
end
end
end

WARNING: ABOVE CODE TYPED FROM MEMORY WITH A TODDLER'S HELP

Thanks MarkusQ!

T.

--
( o _
// trans.
/ \ (e-mail address removed)

I don't give a damn for a man that can only spell a word one way.
-Mark Twain
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,414
Latest member
djangoframe

Latest Threads

Top