There is a method that looks like:
def some_thing(user)
x = user.age
y = 开发者_C百科user.height
end
I have an object that looks like:
x = other.info[0]
y = other.info[1]
How could I pass this information to the method some_thing?
some_thing(other)
won't work as it doesn't have the properties exposed in that manner.
Is it possible to do without modifying the classes and method parameters?
Create an anonymous Struct
to create the properties and use Array
splat to fill them:
some_thing(Struct.new(:age, :height).new(*other.info))
精彩评论