Re: Ruby doesn't implement x++ for Fixnum's because ???
- From: Rajinder Yadav <devguy.ca@xxxxxxxxx>
- Date: Fri, 30 Oct 2009 13:41:03 -0500
On Fri, Oct 30, 2009 at 1:51 PM, lith <minilith@xxxxxxxxx> wrote:
IMHO the story goes like this: absence of postfix ++ and -- is a
consequence of the fact that numeric types are immutable in Ruby which
makes an assignment necessary for these operators.
You could "decorate" it with such a method though. This could look
something like this:
class FixNum < BasicObject
def initialize(fn)
@fn = fn
end
def succ!
@fn += 1
end
def method_missing(*args, &block)
@fn.send(*args, &block)
end
Hi lith,
can you extol your knowledge on me about what method_missing is doing?
I get what *args and &block is, but not quite sure what's going on?
end
a = FixNum.new(1)
a.succ!
p a
=> 2
Whether this is good practice or marginally useful ...
--
Kind Regards,
Rajinder Yadav
http://DevMentor.org
Do Good! - Share Freely, Enrich and Empower people to Transform their lives.
- Follow-Ups:
- Re: Ruby doesn't implement x++ for Fixnum's because ???
- From: Marnen Laibow-Koser
- Re: Ruby doesn't implement x++ for Fixnum's because ???
- References:
- Ruby doesn't implement x++ for Fixnum's because ???
- From: RichardOnRails
- Re: Ruby doesn't implement x++ for Fixnum's because ???
- From: RichardOnRails
- Re: Ruby doesn't implement x++ for Fixnum's because ???
- From: Robert Klemme
- Re: Ruby doesn't implement x++ for Fixnum's because ???
- From: lith
- Ruby doesn't implement x++ for Fixnum's because ???
- Prev by Date: Re: How do you get the tail end of a string?
- Next by Date: Guest+House+Karachi+Gulshan+Johar+Dha+Clifton+North-Nazimabad
- Previous by thread: Re: Ruby doesn't implement x++ for Fixnum's because ???
- Next by thread: Re: Ruby doesn't implement x++ for Fixnum's because ???
- Index(es):
Relevant Pages
|