------art_74678_14653452.1186445765316
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 8/6/07, dblack / rubypal.com <dblack / rubypal.com> wrote:
>
> Hi --
>
> On Tue, 7 Aug 2007, Gary Wright wrote:
>
> > On Jul 25, 2007, at 4:43 PM, dblack / wobblini.net wrote:
> >> I think it's useful to
> >> know that you're passing references around:
> >>
> >>  a  abc"
> >>  b  
> >>  b << "def"
> >>  a          # "abcdef"
> >>
> >> vs. immediate values (symbols, integers), though of course it does all
> >> indeed converge on objects.
> >>
> >
> > I go even farther and simply think of symbols and integers to also be
> > references.  Within that context, the literal 1 is simply a textual
> > representation of a reference to the object that behaves like the
> integer 1.
> > The fact that the Ruby interpreter doesn't actually allocate memory for
> > the object itself is just an implementation detail.
>
> I'd agree about the literal 1 in comparison with other literals:
>
>    1        # textual representation of that object
>    "hi"     # textual representation of that object
>    [1,2,3]  # etc.
>
> but if you do this:
>
>    a  
>    b  hi"
>
> now a (as I understand it) is actually bound to the integer 1, while b
> is bound to a reference to the object.  (I can't say "A reference to
> 'hi'" since that 'hi' would be a different one.... :-)
>
> The reason I think it can be good to keep that difference in view is
> that it has some explanatory power -- especially when the question
> arises about why there's no a++ (which, because a *is* 1, would be
> like 1++).



If 1 and "hi" were methods, they might look like this:

val  
define_method(:one) { val }

define_method(:hi) { val  tring.new; val[0]  h; val[1]  i; val }

a  ne()
b  i()
c  i()
d  ne()

this seemed to illustrate it better in my head. Seeing it typed out, it
doesn't look so insightful. I guess what I'm trying to say is. don't think
of literals as ways of referring to objects, think of them as method calls
that return objects. Or something like that.


David
>
> --
> * Books:
>    RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
>    RUBY FOR RAILS (http://www.manning.com/black)
> * Ruby/Rails training
>      & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)
>
>

------art_74678_14653452.1186445765316--