The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Needed: New Option for Conditional Assignments in Ruby

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Benjamin Booth

Posts: 238
Nickname: benthere
Registered: Feb, 2005

Benjamin Booth is software architect, programmer, web developer and entreprenuer.
Needed: New Option for Conditional Assignments in Ruby Posted: Feb 1, 2011 1:43 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Benjamin Booth.
Original Post: Needed: New Option for Conditional Assignments in Ruby
Feed Title: Table or Booth?
Feed URL: http://www.benjaminbooth.com/tableorbooth/atom.xml
Feed Description: pick_booth() # Ben on software and restaurant seating
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Benjamin Booth
Latest Posts From Table or Booth?

Advertisement

In the next version of Ruby I'd like to be able to have @number in this:

# ... in a class instance ...
@number = 1
# ...

def foo(number = 2)
  @number =|| number
end

evaluate to this:

foo
=> 2

This is nice when you want to override a class instance variable only if a non-null argument is passed. Otherwise, I commonly have to do assignments like this:

def foo(number = 2)
  @number = number || @number
end

Uuugly.  What say you?

Read: Needed: New Option for Conditional Assignments in Ruby

Topic: Needed: New Option for Conditional Assignments in Ruby Previous Topic   Next Topic Topic: RDoc 3.5

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use