craig duncan <duncan / nycap.rr.com> writes:

> (I'm assuming that: b = 'c' creates object `b' as an instance of
> class String. . . which i certainly _hope_ is correct :)

Not quite.

   'c'  creates an object of class String when it is evaluated. It
        creates a new object each time it is evaluated.

    b = 'c'
        assigns a reference to this string object to the variable
        'b'. 'b' is not the object itself, but rather a reference to
        it.

We can confirm this

    a = 'cat'          |a|  ->   String:cat
                             /
    b = a              |b|  -

At this point, both a and b are references to the same object, so

    a[0] = 'b'

    puts b             #=> "bat"

The assignment invokes the [] method in the string object, changing its 
contents. As 'b' references the same object, when you get it's value
you see the change.

Now, back to the rest of your post...

> In some of the previous "Hash access method" threads i've seen this sort
> of thing:
> 
> a = "#{b}"

This assigns the string representation of b to a. It is equivalent to

 a = b.to_str

For example

  class Fred
    def to_s
      "yabba dabba do"
    end
  end

  f = Fred.new

  b = "#{f}"              ( b => "yabba dabba do")
  c = f.to_s              ( c => "yabba dabba do")


If you want to assign the value of 'b' to 'a', just use 'a = b'.

What about eval? Well, what's the value of evaluating 'b'? It's
whatever object b references, so

  a = 123
  b = eval 'a'

Sets 'b' to the value of 'a' (Fixnum:123).

Eval can come in useful though when you don't know the name of the
variable you want to use. For example

  f = "Fred"
  b = "barney"

  for who in ["f", "b"]
    name = eval "#{who}"
    puts name
  end

#=>
  Fred
  barney


Note the extra level of indirection in the string we pass to eval.


Regards


Dave