From: Matthew Kerwin Date: 2013-02-04T16:20:19+09:00 Subject: Re: Confusion with Enum#with_object block argument construct --f46d042ef591c9f98e04d4e0ec46 Content-Type: text/plain; charset=ISO-8859-1 On 4 February 2013 17:02, Love U Ruby wrote: > > Can anyone help me on my question- A. This is a but confusing for me > being a new ruby student? > I have a little difficulty understanding exactly what you're asking, but I'll try to help: > (A) from the source code, Is there any way to get the right construct rather blind try. I started by Googling 'ruby array each_cons', which lead me to < http://ruby-doc.org/core-1.9.3/Enumerable.html> which says that each_cons without a block returns an enumerator. I then searched for 'ruby enumerator with_object' which lead me to < http://ruby-doc.org/core-1.9.3/Enumerator.html#method-i-with_object> The method signature for Enumerator#with_object states: with_object(obj) {|(*args), obj| ... } which tells me straight away that the _last_ block parameter is the object I passed to #with_object, and the other args are the elements over which I'm iterating. The example given is slightly abstract, as it demonstrates the version of #with_object without a block argument, but it still shows that: ...with_object("foo") {|x,string| puts "#{string}: #{x}" } outputs foo: x1 foo: x2 etc. > But in the doc there was several methods for which no example given. If there is no example, you should read the description. If there is no description and no example, the simplest thing to do is either: try it yourself, or come here and ask us. Poor or missing documentation, especially in the core libraries, is definitely grounds for filing a bug report. -- Matthew Kerwin, B.Sc (CompSci) (Hons) http://matthew.kerwin.net.au/ ABN: 59-013-727-651 "You'll never find a programming language that frees you from the burden of clarifying your ideas." - xkcd --f46d042ef591c9f98e04d4e0ec46 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 4 February 2013 17:02, Love U Ruby &l= t;lists@ruby-foru= m.com> wrote:

Can anyone help me on my question- A. This is a but confusing for me<= br> being a new ruby student?
=
I have a little difficulty under= standing exactly what you're asking, but I'll try to help:

>=A0(A)=A0from the source code, Is there any way to get=A0= the righ= t construct rather blind try.

I sta= rted by Googling 'ruby array each_cons', which lead me to <http://ruby-doc.org/c= ore-1.9.3/Enumerable.html> which says that each_cons without a block= returns an enumerator. =A0I then searched for 'ruby enumerator with_ob= ject' which lead me to <http://ruby-doc.org/core-1.9.3/Enumerat= or.html#method-i-with_object>

The method signature for Enumerator#with_object states:
=A0=A0with_object(obj) {|(*args), = obj| ... }
which tells me straight away that the _last_ block parameter is = the object I passed to #with_object, and the other args are the elements ov= er which I'm iterating.

The example give= n is slightly abstract, as it demonstrates the version of #with_object with= out a block argument, but it still shows that:
=A0 =A0 ...with_object("foo") {|x,string| puts "#= {string}: #{x}" }
outputs
=A0 =A0 foo:= x1
=A0 =A0 foo: x2
etc.
>=A0But in the doc there was several methods for which no=A0example given.

If there is no example, you should read the descriptio= n. If there is no description and no example, the simplest thing to do is e= ither: try it yourself, or come here and ask us.

Poor or missing documentation, especially in the core libraries,= is definitely grounds for filing a bug report.

-= -
=A0 Matthew Kerwin, B.Sc (CompSci) (Hons)
=A0 http://matthew.kerwin.net.au/ =A0 ABN: 59-013-727-651

=A0 "You'll never find a programmin= g language that frees
=A0 you from the burden of clarifying your ideas.&= quot; - xkcd
--f46d042ef591c9f98e04d4e0ec46--