LWN.net Logo

Ruby 2.0.0 released

Ruby 2.0.0 released

Posted Feb 24, 2013 16:11 UTC (Sun) by marduk (subscriber, #3831)
In reply to: Ruby 2.0.0 released by tnoo
Parent article: Ruby 2.0.0 released

I too like Python but, unless I'm missing something horribly obvious here, it doesn't appear that much different than how Python does it.. they use ":" instead of "=". The "**" syntax is identical to Python AFAICT.


(Log in to post comments)

Ruby 2.0.0 released

Posted Feb 24, 2013 16:47 UTC (Sun) by tnoo (subscriber, #20427) [Link]

Ruby
def cycle(first_value, *values)
  options = values.extract_options!
  name = options.fetch(:name, 'default')

Python
def cycle(first_value, name=default):

or alternatively

def cycle(first_value, **values):
  name = values.get('name', 'default')

Both Python versions looks much simpler to me.

Ruby 2.0.0 released

Posted Feb 24, 2013 16:56 UTC (Sun) by imgx64 (guest, #78590) [Link]

That's the old way of using keyword arguments. The new way, as the article points out:
# Ruby 2.0:
def cycle(first_value, *values, name: 'default')
  # ...
end

Ruby 2.0.0 released

Posted Feb 25, 2013 7:47 UTC (Mon) by tnoo (subscriber, #20427) [Link]

Ooops, you're correct, I read that article too hastily. In this case I'm glad to see sane syntax being used consistently.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds