@roar = v
trex = Carnivore.new
trex.roar = "GRRRxxz"
IRB has nothing to do with this. It's a feature of ruby called "open classes"
So when you first load your
Carnivore class, it is loaded in its entirety, because it didn't exist before. But if you then remove a method in a file and reload it, what happens is ruby opens your class and adds a getter method. Which it already had, so it's overwritten. Which explains why changes to method bodies (your
puts there) are reflected.
This technique is what powers so-called "monkey-patching". You can patch any class in ruby, even a system one.
class String def pirate self + ', arrrr!' end end 'hello'.pirate # => "hello, arrrr!"
You see, it "patches" an existing class. If this class definition replaced/shadowed the one from the system, your app would be pretty broken.