For class variables, the assignment is klass.foo = 'bar'indeed the syntactic sugar for the method call klass.foo=(bar). But if I assign a local variable as follows:
irb(main):001:0> foo = 'bar'
=> "bar"
Then what object is assigned to this variable? Does this also call a method foo=? I would kind of expect this because:
In Ruby, everything is an object. Each piece of information and code can be provided with its own properties and actions.
In my opinion, this will mean one (or possibly several) βmagicβ root object (s), under which everything else is defined (... but perhaps this mental image is erroneous ...)
I tried:
irb(main):002:0> Kernel.foo
NoMethodError: undefined method `foo' for Kernel:Module
irb(main):003:0> Object.foo
NoMethodError: undefined method `foo' for Object:Class
irb(main):004:0> self.foo
NoMethodError: undefined method `foo' for main:Object
The same applies to code, for example:
def foo
a = 'bar'
puts self.a
end
foo
which gives me:
a.rb:3:in `foo': undefined method `foo' for main:Object (NoMethodError)
from foo.rb:6:in `<main>'