[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Bug or on purpose?

Joao Pedrosa

5/4/2005 3:54:00 PM

Hi,

dewd@heaven:~ $ ruby -v
ruby 1.9.0 (2005-05-01) [i686-linux]
dewd@heaven:~ $ irb
irb(main):001:0> def opa s
irb(main):002:1> 'z'
irb(main):003:1> end
=> nil
irb(main):004:0> opa 'kct'
=> "z"
irb(main):005:0> opa = opa('kct')
NoMethodError: undefined method `call' for nil:NilClass
from (irb):5
irb(main):006:0> exit
dewd@heaven:~ $

I tested it on Windows and on Linux with Ruby CVS-HEAD:
dewd@heaven:~ $ ruby -v
ruby 1.9.0 (2005-05-01) [i686-linux]

Is it on purpose? Because it breaks some code in at least a lib that I
know of (in rakewx.rb from wxRuby).

Cheers,
Joao



12 Answers

Robert Klemme

5/4/2005 3:59:00 PM

0

Joao Pedrosa wrote:
> Hi,
>
> dewd@heaven:~ $ ruby -v
> ruby 1.9.0 (2005-05-01) [i686-linux]
> dewd@heaven:~ $ irb
> irb(main):001:0> def opa s
> irb(main):002:1> 'z'
> irb(main):003:1> end
> => nil
> irb(main):004:0> opa 'kct'
> => "z"
> irb(main):005:0> opa = opa('kct')
> NoMethodError: undefined method `call' for nil:NilClass
> from (irb):5
> irb(main):006:0> exit
> dewd@heaven:~ $
>
> I tested it on Windows and on Linux with Ruby CVS-HEAD:
> dewd@heaven:~ $ ruby -v
> ruby 1.9.0 (2005-05-01) [i686-linux]
>
> Is it on purpose? Because it breaks some code in at least a lib that I
> know of (in rakewx.rb from wxRuby).

Dunno...

Additional note: 1.8.2 doesn't show this behavior. But: never trust IRB
when it comes to local variables. Did you also try that in a script or
with ruby -e '...'?

Kind regards

robert

Austin Ziegler

5/4/2005 4:06:00 PM

0

On 5/4/05, Joao Pedrosa <joaopedrosa@gmail.com> wrote:
> dewd@heaven:~ $ ruby -v
> ruby 1.9.0 (2005-05-01) [i686-linux]
> dewd@heaven:~ $ irb
> irb(main):001:0> def opa s
> irb(main):002:1> 'z'
> irb(main):003:1> end
> => nil
> irb(main):004:0> opa 'kct'
> => "z"
> irb(main):005:0> opa = opa('kct')
> NoMethodError: undefined method `call' for nil:NilClass
> from (irb):5
> irb(main):006:0> exit

This looks like a bug in an on-purpose experimental feature.

-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca



Joao Pedrosa

5/4/2005 4:16:00 PM

0

Hi,

> Additional note: 1.8.2 doesn't show this behavior. But: never trust IRB
> when it comes to local variables. Did you also try that in a script or
> with ruby -e '...'?

dewd@heaven:~ $ ruby -e "def foo s; 'bar'; end; foo = foo('z')"
-e:1: undefined method `call' for nil:NilClass (NoMethodError)

This behaviour I encountered when I was trying to compile wxRuby on
Windows. :-)

Cheers,
Joao



Joe Van Dyk

5/4/2005 4:17:00 PM

0

On 5/4/05, Austin Ziegler <halostatue@gmail.com> wrote:
> On 5/4/05, Joao Pedrosa <joaopedrosa@gmail.com> wrote:
> > dewd@heaven:~ $ ruby -v
> > ruby 1.9.0 (2005-05-01) [i686-linux]
> > dewd@heaven:~ $ irb
> > irb(main):001:0> def opa s
> > irb(main):002:1> 'z'
> > irb(main):003:1> end
> > => nil
> > irb(main):004:0> opa 'kct'
> > => "z"
> > irb(main):005:0> opa = opa('kct')
> > NoMethodError: undefined method `call' for nil:NilClass
> > from (irb):5
> > irb(main):006:0> exit
>
> This looks like a bug in an on-purpose experimental feature.
>

Can someone fill me in on what's going on here?

It looks like the code reads something like:

def opa(s)
'z'
end

So,
opa('kct')
should return 'z'.

But I have no idea what
opa = opa('kct')
is trying to do.



Mark Hubbart

5/4/2005 4:18:00 PM

0

On 5/4/05, Robert Klemme <bob.news@gmx.net> wrote:
> Joao Pedrosa wrote:
> > Hi,
> >
> > dewd@heaven:~ $ ruby -v
> > ruby 1.9.0 (2005-05-01) [i686-linux]
> > dewd@heaven:~ $ irb
> > irb(main):001:0> def opa s
> > irb(main):002:1> 'z'
> > irb(main):003:1> end
> > => nil
> > irb(main):004:0> opa 'kct'
> > => "z"
> > irb(main):005:0> opa = opa('kct')
> > NoMethodError: undefined method `call' for nil:NilClass
> > from (irb):5
> > irb(main):006:0> exit
> > dewd@heaven:~ $
> >
> > I tested it on Windows and on Linux with Ruby CVS-HEAD:
> > dewd@heaven:~ $ ruby -v
> > ruby 1.9.0 (2005-05-01) [i686-linux]
> >
> > Is it on purpose? Because it breaks some code in at least a lib that I
> > know of (in rakewx.rb from wxRuby).
>
> Dunno...
>
> Additional note: 1.8.2 doesn't show this behavior. But: never trust IRB
> when it comes to local variables. Did you also try that in a script or
> with ruby -e '...'?

This looks like it may be the result of a bug in the new proc calling
feature. If I understand correctly, it translates foo(something) into
foo.call(something) where foo is a local variable. And since "opa"
becomes a local variable in that line, it tries to call it, and finds
it to be nil. I think.

cheers,
Mark



dblack

5/4/2005 4:26:00 PM

0

Joe Van Dyk

5/4/2005 4:34:00 PM

0

On 5/4/05, David A. Black <dblack@wobblini.net> wrote:
> Hi --
>
> On Thu, 5 May 2005, Joe Van Dyk wrote:
>
> > Can someone fill me in on what's going on here?
> >
> > It looks like the code reads something like:
> >
> > def opa(s)
> > 'z'
> > end
> >
> > So,
> > opa('kct')
> > should return 'z'.
> >
> > But I have no idea what
> > opa = opa('kct')
> > is trying to do.
>
> It's trying to set a local variable called opa to the result of
> calling (the method) opa with arg 'kct'.

Isn't that illegal? The name 'opa' has already been defined.

/me pulls out copy of ISO Ruby standard.

/me notices that it's missing. :(



Robert Klemme

5/4/2005 4:42:00 PM

0


"Joe Van Dyk" <joevandyk@gmail.com> schrieb im Newsbeitrag
news:c715e640505040933dc1a4a9@mail.gmail.com...
> On 5/4/05, David A. Black <dblack@wobblini.net> wrote:
>> Hi --
>>
>> On Thu, 5 May 2005, Joe Van Dyk wrote:
>>
>> > Can someone fill me in on what's going on here?
>> >
>> > It looks like the code reads something like:
>> >
>> > def opa(s)
>> > 'z'
>> > end
>> >
>> > So,
>> > opa('kct')
>> > should return 'z'.
>> >
>> > But I have no idea what
>> > opa = opa('kct')
>> > is trying to do.
>>
>> It's trying to set a local variable called opa to the result of
>> calling (the method) opa with arg 'kct'.
>
> Isn't that illegal? The name 'opa' has already been defined.

IMHO that's perfectly ok as long as all uses are non ambiguous.

> /me pulls out copy of ISO Ruby standard.
>
> /me notices that it's missing. :(

/me too

But that's also ok and fits well with Ruby's dynamic nature. Hint: no
static typing, no ISO spec. ;-)

Kind regards

robert

dblack

5/4/2005 4:43:00 PM

0

dblack

5/4/2005 5:01:00 PM

0