[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: Need examples comparing Ruby to Python
From: "David A. Black" <dblack () wobblini ! net>
Date: 2004-02-23 15:32:48
Message-ID: Pine.LNX.4.44.0402230726210.13193-100000 () wobblini
[Download RAW message or body]
Hi --
On Mon, 23 Feb 2004, Emmanuel Touzery wrote:
> David MacQuigg wrote:
>
> >I'm putting together a web page comparing Ruby to Python, and I need
> >some good examples showing off the advantages of Ruby. I'm new to
> >Ruby, so all I've been able to do so far is pick some examples from
> >the Programming Ruby book, and do a Google search on "compare ruby
> >python". What I've found is way out-of-date.
> >
> >
> the ruby code could be simplified:
>
> file, length, name, title = line.chomp.split(/\s*\|\s*/)
> name.squeeze!(" ")
> =>
> file, length, name, title =line.split /\|/
> name.strip!
That doesn't do the same thing though:
irb(main):029:0> " Song Title ".strip
=> "Song Title"
irb(main):030:0> " Song Title ".squeeze
=> " Song Title "
> also, if min and sec are numbers, they should be kept in number
> variables imho. but it makes the code look more complicated to newbyes
> so it's discussable:
> mins, secs = length.scan(/\d+/)
> songs.append Song.new(title, name, mins.to_i*60+secs.to_i)
> =>
> mins,secs = length.scan(/\d+/).map {|i| i.to_i}
or:
require 'scanf'
mins,secs = length.scanf("%d:%d")
David
--
David A. Black
dblack@wobblini.net
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic