Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > require!

Reply
Thread Tools

require!

 
 
Ross Bamford
Guest
Posts: n/a
 
      12-01-2005
It (finally) clicked now, 'require' is just a method...

Boy do I feel stupid.

On another note, though, I also found out that calling amethod(*args)
works with anything with 'each' (any Enumerable?), which made me smile. It
was the post about ranges that made me get that

Thanks!

--
Ross Bamford - http://www.velocityreviews.com/forums/(E-Mail Removed)
"\e[1;31mL"
 
Reply With Quote
 
 
 
 
Trans
Guest
Posts: n/a
 
      12-01-2005
Hi Ross, actually as Florian recently taught me, *obj works for any
object with #to_ary defined --if that is what you mean.

T.

 
Reply With Quote
 
 
 
 
gwtmp01@mac.com
Guest
Posts: n/a
 
      12-01-2005

On Nov 30, 2005, at 11:32 PM, Trans wrote:
> Hi Ross, actually as Florian recently taught me, *obj works for any
> object with #to_ary defined --if that is what you mean.


Actually, I think the * operator looks for #to_a not #to_ary.

Gary Wright



 
Reply With Quote
 
Ross Bamford
Guest
Posts: n/a
 
      12-01-2005
On Thu, 01 Dec 2005 04:30:28 -0000, Trans <(E-Mail Removed)> wrote:

> Hi Ross, actually as Florian recently taught me, *obj works for any
> object with #to_ary defined --if that is what you mean.
>
> T.
>


I see... I was pretty happy when I realised it did it at all, and of
course it makes complete sense with hindsight. Thanks for pointing the way.

--
Ross Bamford - (E-Mail Removed)
 
Reply With Quote
 
Ross Bamford
Guest
Posts: n/a
 
      12-01-2005
On Thu, 01 Dec 2005 05:45:53 -0000, <(E-Mail Removed)> wrote:

>
> On Nov 30, 2005, at 11:32 PM, Trans wrote:
>> Hi Ross, actually as Florian recently taught me, *obj works for any
>> object with #to_ary defined --if that is what you mean.

>
> Actually, I think the * operator looks for #to_a not #to_ary.
>
> Gary Wright
>


Some quick experiments just now suggest it looks first for to_ary, then
to_a. As I say, I was pretty pleased to find it did it at all so I didn't
carry on playing with it ...

Cheers,

--
Ross Bamford - (E-Mail Removed)
 
Reply With Quote
 
Lionel Thiry
Guest
Posts: n/a
 
      12-01-2005
Trans a écrit :
> Hi Ross, actually as Florian recently taught me, *obj works for any
> object with #to_ary defined --if that is what you mean.
>
> T.
>


AFAIK may change in ruby2.

--
Lionel Thiry

Personal web site: http://users.skynet.be/lthiry/
 
Reply With Quote
 
David A. Black
Guest
Posts: n/a
 
      12-01-2005
--8323328-248990591-1133437847=:698
Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-248990591-1133437847=:698"

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-248990591-1133437847=:698
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

On Thu, 1 Dec 2005, Lionel Thiry wrote:

> Trans a =E9crit :
>> Hi Ross, actually as Florian recently taught me, *obj works for any
>> object with #to_ary defined --if that is what you mean.
>>
>> T.
>>

>
> AFAIK may change in ruby2.


As Gary says it's actually to_a, not to_ary -- and I think it will
probably still work in 2.x, because Enumerable#to_a is explicitly
defined (not the soon-to-disappear default to_a for all objects).


David

--=20
David A. Black
(E-Mail Removed)
--8323328-248990591-1133437847=:698--
--8323328-248990591-1133437847=:698--


 
Reply With Quote
 
Lionel Thiry
Guest
Posts: n/a
 
      12-01-2005
David A. Black a écrit :
> Hi --
>
> On Thu, 1 Dec 2005, Lionel Thiry wrote:
>
>> Trans a �crit :
>>
>>> Hi Ross, actually as Florian recently taught me, *obj works for any
>>> object with #to_ary defined --if that is what you mean.
>>>
>>> T.
>>>

>>
>> AFAIK may change in ruby2.

>
>
> As Gary says it's actually to_a, not to_ary -- and I think it will
> probably still work in 2.x, because Enumerable#to_a is explicitly
> defined (not the soon-to-disappear default to_a for all objects).
>
>
> David
>


Mmm, I remember Matz wonders about possible changes in the way the array
expansion operator * could work. He wonders if he should differentiate
array [a,b,c] and list a,b,c or not. Until decided, I keep in mind that
the way *args works may change in ruby2.

--
Lionel Thiry

Personal web site: http://users.skynet.be/lthiry/
 
Reply With Quote
 
James Edward Gray II
Guest
Posts: n/a
 
      12-01-2005
On Nov 30, 2005, at 7:52 PM, Ross Bamford wrote:

> On another note, though, I also found out that calling amethod
> (*args) works with anything with 'each' (any Enumerable?), which
> made me smile. It was the post about ranges that made me get that


Actually * looks for a to_a.

James Edward Gray II


 
Reply With Quote
 
Brian Buckley
Guest
Posts: n/a
 
      12-01-2005
> Actually * looks for a to_a.

Does calling amethod(*x) have the same meaning as calling
amethod(x.to_a)? If is it what is the benefit of using the (less
clear) first way?

Brian Buckley


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments