3 ms·
This depends on what you mean by "I'll never get two objects in Ruby that can't be used the same way because their system of construction is different." You hav
by chc 16y ago
This depends on what you mean by "I'll never get two objects in Ruby that can't be used the same way because their system of construction is different." You have very few guarantees in Ruby, even fewer than in JavaScript.
new_number = Fixnum.new # FUUUUUUUUUU-
# Well, OK…
new_number = Integer.new # OK, seriously?
# Fine, then. Maybe some specialized classes are exceptions.
this_should_work_right = BasicObject.new
# Ah, it worked!
puts this_should_work_right # WTMFH?!?!?!?!
ClassA = Struct.new(:name, :age)
ClassB = Class.new {attr_accesor :name, age}
a = ClassA.new
b = ClassB.new
a[:name], a[:age] = 'Fred', 42
b[:name], b[:age] = 'Rick', 24 # Won't work
- bodhi 16y agoIt took me a while to figure out how your comment was relevant to your parent, when I realised that you interpreted "system of construction" differently. (I humbly posit that) You are demonstrating how to create an instance of a Struct or Class, whereas the parent's intent was how the Struct or Class is implemented behind the curtain.