ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: Ruby doesn't implement x++ for Fixnum's because ???
by Tony Arcieri other posts by this author
Nov 8 2009 11:32AM messages near this date
Re: Ruby doesn't implement x++ for Fixnum's because ??? | Re: Ruby doesn't implement x++ for Fixnum's because ???
On Sun, Nov 8, 2009 at 12:20 PM, Seebs <usenet-nospam@[...].net>  wrote:

>  I don't think that gives the right semantics in many cases.  It's also
>  not clear that rebinding works:
> 
>         array_example.length++
> 
>  What should this do?
> 

Well, this is a very interesting question, as I discovered something about
Ruby I didn't know from this...

Say we have:

class Foo
  attr_reader :bar

  def initialize
    @bar = 0
  end
end

f = Foo.new
f.bar += 1

What do you think the value of a subsequent call to f.bar will be?

I was surprised to discover that it indeed 1.  Somehow += is mutating the
ivar through a supposed "attr_reader" even though there is no corresponding
bar= method.  In that case += appears to be frobbing the ivar directly.

Very strange.  Even worse:

class Foo
  def initialize
    @bar = 0
  end

  def bar
    @bar + 1
  end
end

f = Foo.new
f.bar += 1

Now what do you think the value of a subsequent call to f.bar will be?

Indeed, it would be 3!

I cannot begin to answer this question because Ruby is doing strange and
unexpected things here, at least from my perspective...

-- 
Tony Arcieri
Medioh/Nagravision
Thread:
RichardOnRails
Gavin Sinclair
Marnen Laibow-Koser
Tony Arcieri
David A. Black
T3ch.Dude
TonyMc
Tony Arcieri
James Edward Gray II
Seebs
Aldric Giacomoni
Sebastian Hungerecker
Aldric Giacomoni
Seebs
Seebs
Joshua Ballanco
Michael W. Ryder
Seebs
Rick DeNatale
Marnen Laibow-Koser
Aldric Giacomoni
Marnen Laibow-Koser
Aldric Giacomoni
Rick DeNatale
Aldric Giacomoni
Rick DeNatale
Aldric Giacomoni
Rick DeNatale
David A. Black
Aldric Giacomoni
Marnen Laibow-Koser
Marnen Laibow-Koser
Seebs
Seebs
Seebs
Gavin Sinclair
Tony Arcieri
Joel VanderWerf
Tony Arcieri
Marnen Laibow-Koser
Aldric Giacomoni
Tony Arcieri
Aldric Giacomoni
Phrogz
Ralph Shnelvar
Tony Arcieri
Tony Arcieri
Marnen Laibow-Koser
Tony Arcieri
Marnen Laibow-Koser
Tony Arcieri
Joshua Ballanco
Tony Arcieri
Seebs
Tony Arcieri
Seebs
Tony Arcieri
Tony Arcieri
Seebs
Seebs
RichardOnRails
David A. Black
Marnen Laibow-Koser
Seebs
Tony Arcieri
Rick DeNatale
Tony Arcieri
Rick DeNatale
Tony Arcieri
Marnen Laibow-Koser
Tony Arcieri
Walton Hoops
Tony Arcieri
Walton Hoops
Tony Arcieri
Florian Assmann
Marnen Laibow-Koser
Walton Hoops
Seebs
David A. Black
Gavin Sinclair
Gavin Sinclair
Gavin Sinclair
Tony Arcieri
David A. Black
Tony Arcieri
David A. Black
Yukihiro Matsumoto
Seebs
RichardOnRails
RichardOnRails
Martin DeMello
Aldric Giacomoni
Seebs
RichardOnRails
RichardOnRails
David A. Black
Seebs
Rick DeNatale
Seebs
Seebs
Lith
Gavin Sinclair
Tony Arcieri
Walton Hoops
Michael W. Ryder
Walton Hoops
Michael W. Ryder
Marnen Laibow-Koser
Walton Hoops
Michael W. Ryder
Walton Hoops
Matthew K. Williams
Marnen Laibow-Koser
Michael W. Ryder
David A. Black
David A. Black
Michael W. Ryder
Marnen Laibow-Koser
Tony Arcieri
Marnen Laibow-Koser
Tony Arcieri
David A. Black
Aldric Giacomoni
Martin DeMello
Tony Arcieri
Tony Arcieri
Martin DeMello
Paul Smith
Tony Arcieri
Seebs
Rick DeNatale

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved