Re: Ruby For Rails Question

So reverse is not a method on end object? It can be
end.any_method_that_is_available_in_the_return_object?

b is the block param for the second block (the one that goes with
select). The reverse reverses the results up to that point.

Basically it’s a chain of array transformations.

David

Hi –

On Wed, 11 Oct 2006, Bala P. wrote:

So reverse is not a method on end object? It can be
end.any_method_that_is_available_in_the_return_object?

Right. end is not an object; it signals the end of the code block.

David


David A. Black | [email protected]
Author of “Ruby for Rails” [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB’s Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

What’s the example data look like? Can someone share an end to end
example? I’m curious.

At 10:27 PM -0400 10/11/06, x1 wrote:

What’s the example data look like? Can someone share
an end to end example? I’m curious.

Sure.

-r

% cat r4r_415
#!/usr/bin/env ruby

r4r_415 - test code from p. 415 of “Ruby for Rails”

def main
puts rank( %w{a b a c i d a r i a n} ).join(’, ')
end

def rank(list)
list.uniq.sort_by do |a|
list.select do |b|
a == b
end.size
end.reverse
end

main

% r4r_415
a, i, d, r, c, b, n

http://www.cfcl.com/rdm Rich M.
http://www.cfcl.com/rdm/resume [email protected]
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Technical editing and writing, programming, and web development

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs