ruby 1.8 differences?

G

Glenn

Can anybody point me at a list of what's changed in Ruby
version-for-version? I'm reading the web-based docs and I'd like to
know what's improved in the version I've started using (1.8.13rc2 as
of yesterday if memory serves). On Windows (he ducks)...!
 
J

Jean-Hugues ROBERT


This is incredibly useful ! I specially liked the sort_by thing.

I started refactoring my code to use it. But I use a lot of sort!()
and sort_by! does not exists :-(

Question : Why no sort_by!() ?
Nota: Maybe I should not use sort!() that much. In some cases
I am assuming that it will be more efficient than x = x.sort(),
but I may be wrong.

initialize_copy() is great too. For a long time I was unsure
about how to implement copy constructors. Most of the time
my initialize() had to look at its parameters to figure out
what to do and to copy construct if one its parameter was
another object to use as a prototype. Now, I can get rid of
that ugly code.

Yours,

Jean-Hugues
 
F

Florian Frank

I started refactoring my code to use it. But I use a lot of sort!()
and sort_by! does not exists :-(

Question : Why no sort_by!() ?

sort_by is a more efficent way of Schwartzian Transform (because it's
implemented in C). So instead of

ary.map {|x| [f(x), x] }.sort {|(ka,),(kb,)| ka <=> kb }.map { |k,v| v }

you can just write:

ary.sort_by { |x| f(x) }

Temporary arrays are created anyway. That's why it is not useful to have
sort_by!. In general Schwartzian Transform is a stupid idea, especially
for large arrays, but sometimes it's possible to find a function f with
an image that can be used for comparing the values more efficiently than
the values themselves.

Here's a perl-centered paper about a lot of sorting tricks, but most of
it is also true for Ruby: "A Fresh Look at Efficient Perl Sorting",
http://www.sysarch.com/perl/sort_paper.html
 
D

daz

I tried Symbol#intern, strangely it is not defined for me...
So I keep my "class Symbol; def intern() self end end"
RUBY_VERSION == "1.8.1", RUBY_PLATFORM == "i386-mswin32"
Typo ?

Yours,

Jean-Hugues

#to_sym seems to be preferred over #intern.

h = 'Hello'.to_sym

p h # (from String) #-> :Hello
p h.to_sym # (from Symbol) #-> :Hello
p h.to_i.to_sym # (from Fixnum) #-> :Hello


<doc\ChangeLog>

Sat Nov 2 00:38:55 2002 Yukihiro Matsumoto <[email protected]>

* object.c (sym_to_sym): rename from Symbol#intern
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top