On Thu, Dec 19, 2013 at 11:29 PM, Jason Tao <jtao / digital-dispatch.com> wro=
te:

> Now I am clear for Fixnum, operators create new object instead of operate=
 on
> the current one (immutable J), and assignment changed the reference. At
> least as of now I haven=92t found a method to change the Fixnum object
> directly. For String, there are methods/operators operate on the current
> object (mutable).

From a language user's point of view _all_ variables are references.
Technically (i.e. under the hood) there are some optimizations done -
but they do not affect usage.  I'd say it's best to ignore the under
the hood part for now while you are learning the language.  It may
cause unnecessary confusion.  You can still look at this later.

To add a fun fact: you can actually attach state to a Fixnum:

irb(main):017:0> x=3D1
=3D> 1
irb(main):018:0> x.instance_variable_set '@foo', "bar"
=3D> "bar"
irb(main):019:0> x.instance_variable_get '@foo'
=3D> "bar"
irb(main):020:0> 1.instance_variable_get '@foo'
=3D> "bar"
irb(main):021:0> 1.freeze
=3D> 1
irb(main):022:0> x.instance_variable_set '@foo', "buz"
RuntimeError: can't modify frozen object
from (irb):22:in `instance_variable_set'
from (irb):22
from /usr/bin/irb:12:in `<main>'

That does not mean that you should do it or that it's a good idea. For
all practical purposes you should view all numeric types as immutable.
 A bit more on numbers and operators in Ruby:

http://blog.rubybestpractices.com/posts/rklemme/019-Complete_Numeric_Class.=
html

Kind regards

robert


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/