eigenclass logo
MAIN  Index  Search  Changes  PageRank  Login

What's new in Ruby 1.9, Feb. 07 update

Yet another update to the list of changes in Ruby 1.9, covering new stuff between Oct. 06 and Jan. 07.

There are two major events which you won't find in that list (since they don't affect the language itself) but deserve nonetheless a mention. In Dec. 06 Koichi Sasada migrated Ruby's source repository to Subversion, paving the way for the merge of YARV*1 with Ruby 1.9, which was performed on Jan 01 00:00:00 2007 according to the ChangeLog. matz is now also working on a separate branch (matzruby), with more experimental features.

These are the most relevant language/core modifications during the covered period of time:

Symbol

It isn't a subclass of String anymore. This experiment lived exactly for two months (Sep. 2nd to Nov. 2nd).

Method#receiver, #name and #owner

Returns the receiver of a Method object, the name and the class or module where it was defined, respectively.

class A; def foo; end end
a = A.new
a.method(:foo).receiver                # => #<A:0xa7d3c938>
a.method(:foo).owner                   # => A
a.method(:foo).name                    # => "foo"

Line length limit in IO operations

IO operations that read a line accept an argument to specify the maximum amount of data to be read.

The affected methods are IO#gets, IO#readline, IO#readlines, IO#each_line, IO#lines, IO.foreach, IO.readlines, StringIO#gets, StringIO#readline, String IO#each and StringIO#readlines.

The limit is specified either as the (optional) second argument, or by passing a single integer argument (i.e. the first argument is interpreted as the limit if it's an integer, as a line separator otherwise)

IO#lines and IO#bytes

These new methods behave like String#lines and #bytes (also new in 1.9), returning an enumerator.

String#unpack with a block

If given a block, String#unpack will call it with the unpacked values instead of creating an array.

RUBY_VERSION                                      # => "1.9.0"
RUBY_RELEASE_DATE                                 # => "2007-02-07"
s = (0..4).to_a.pack("V*")
a = []
s.unpack("V*"){|x| a << x}
a                                                 # => [0, 1, 2, 3, 4]

String#lines

String#lines accepts an extra argument to indicate the line separator.

If given a block, #lines behaves like #each_line (ruby-core:9218).

Object#tap

Passes the object to the block and returns it (meant to be used for call chaining):

"F".tap{|x| x.upcase!}[0]                       # => "F"
# Note that "F".upcase![0] would fail since upcase! would return nil in this
# case.

Other methods

See the full list for more information.

  • Kernel#to_splat
  • Integer#pred
  • String#hash
  • Dir.exist?
  • File.exists?


tap - Justin (2007-02-07 (Wed) 15:48:24)

Did MentalGuy get some credit for inventing this technique? It's awesome!

http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions

MenTaLguY 2007-02-07 (Wed) 17:31:10

It's been independently invented by a number of people over the years, although I don't know of anyone else who called it "tap".

Perhaps I get partial credit for popularizing the name. :)


css - yxhuvud (2007-02-08 (Thr) 05:13:44)

You have some weird stuff going on with your css. When I put my mouse over the black coding blocks, stuff that probably shouldn't happen happen.

mfp 2007-02-08 (Thr) 06:53:39

This is what is meant to happen: code blocks expanding horizontally so you can read overflowing lines easily. Works for me on Firefox & Safari. What are you getting?

Celti 2007-02-08 (Thr) 07:04:21

I get the inverse - the block contracts, covering overflowing lines (if any exist). I doubt that's supposed to happen.

An unrelated question: Are we going to see a version of ruby-wmii for wmii 3.5/3.6, or not until 4.0 is released?

mfp 2007-02-08 (Thr) 15:52:14

Let me guess: 0.9 * (1 - 0.27) = 0.657 of your screen > 900 pixels, so your horizontal resolution is over 1360 pixels? The width for pre:hover is currently set to 900px, I'll change that.

There will probably be a ruby-wmii for 3.6, since we don't know how long 4.0 will take. I'll have to bite the bullet and port to 3.6's FS, in the knowledge that 4.0 will change everything again :|. No 3.5 because it introduces several bugs 3.1 didn't have...


thanks - Steven A Bristol (2007-02-08 (Thr) 08:02:35)

Thanks for this info. It is a great service you are providing to the REST of us!


Regd: Documentation - Anonymous (2007-04-21 (Sat) 04:22:10)

IO.readlines("/tmp/rel.notes"



Last modified:2007/02/07 08:24:11
Keyword(s):[blog] [ruby] [frontpage] [1.9] [changelog]
References:

*1 not to be called that way anymore, being the Ruby VM