[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

This is wierd...

Robert H

1/24/2005 1:50:00 PM

I just installed 1.8.2 to get a feel for Ruby. I tried the hello.rb
file.

This works:
class Hello

attr_reader :msg

def initialize

@msg = "Hello, World"

end

end

h = Hello.new

puts h.msg

print "Press RETURN"

$stdin.gets

This does not:

class Hello
attr_reader :msg

def initialize
@msg = "Hello, World"
end
end

h = Hello.new
puts h.msg
print "Press RETURN"
$stdin.gets

hello.rb:2: formal argument cannot be an instance variable
It is the same code except the spacing. What is the deal?

Robert

5 Answers

Joao Pedrosa

1/24/2005 2:09:00 PM

0

Hi,

> hello.rb:2: formal argument cannot be an instance variable
> It is the same code except the spacing. What is the deal?

You are probably on Windows, right?

What version of Ruby have you got?

Mine is: ruby 1.9.0 (2005-01-15) [i686-linux]

and I couldn't reproduce this error.

Cheers,
Joao


Jamis Buck

1/24/2005 2:10:00 PM

0

On 22:50 Mon 24 Jan , sigzero@gmail.com wrote:
> I just installed 1.8.2 to get a feel for Ruby. I tried the hello.rb
> file.
>
> This works:
> class Hello
>
> attr_reader :msg
>
> def initialize
>
> @msg = "Hello, World"
>
> end
>
> end
>
> h = Hello.new
>
> puts h.msg
>
> print "Press RETURN"
>
> $stdin.gets
>
> This does not:
>
> class Hello
> attr_reader :msg
>
> def initialize
> @msg = "Hello, World"
> end
> end
>
> h = Hello.new
> puts h.msg
> print "Press RETURN"
> $stdin.gets
>
> hello.rb:2: formal argument cannot be an instance variable
> It is the same code except the spacing. What is the deal?

Both versions worked for me. :(

Can anyone else duplicate the problem?

- Jamis

--
Jamis Buck
jamis_buck@byu.edu
http://jamis.jam...
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."



Andreas Semt

1/24/2005 2:52:00 PM

0

sigzero@gmail.com wrote:

> I just installed 1.8.2 to get a feel for Ruby. I tried the hello.rb
> file.
>
> This works:
> class Hello
>
> attr_reader :msg
>
> def initialize
>
> @msg = "Hello, World"
>
> end
>
> end
>
> h = Hello.new
>
> puts h.msg
>
> print "Press RETURN"
>
> $stdin.gets
>
> This does not:
>
> class Hello
> attr_reader :msg
>
> def initialize
> @msg = "Hello, World"
> end
> end
>
> h = Hello.new
> puts h.msg
> print "Press RETURN"
> $stdin.gets
>
> hello.rb:2: formal argument cannot be an instance variable
> It is the same code except the spacing. What is the deal?
>
> Robert
>
>
>
>

Hello Robert!

i am on W2K Pro, Ruby:
ruby 1.8.2 (2004-07-29) [i386-mswin32].
Both versions of your code works for me.

Greetings,
Andreas


Csaba Henk

1/24/2005 2:55:00 PM

0

On 2005-01-24, sigzero@gmail.com <sigzero@gmail.com> wrote:
> I just installed 1.8.2 to get a feel for Ruby. I tried the hello.rb
> file.
>
> This works:
> class Hello

[snip]

> This does not:
>
> class Hello

Just a simple test, to avoid unnecessary hairtearing.

It happens me from time to time that due to non-intentionally pressing
some stupid keycombination, a non-printable character finds its way to
my code, and then ruby mystically chokes on it (the terminal doesn't
show any weird upon this).

Then I check my file foo.rb with "ruby -ne 'p $_' foo.rb", and I
immediately see if this is the case.

Csaba

WATANABE Hirofumi

1/24/2005 3:18:00 PM

0

Hi,

sigzero@gmail.com <sigzero@gmail.com> writes:

> class Hello
> attr_reader :msg
>
> def initialize
> @msg = "Hello, World"
> end
> end
>
> h = Hello.new
> puts h.msg
> print "Press RETURN"
> $stdin.gets
>
> hello.rb:2: formal argument cannot be an instance variable
> It is the same code except the spacing. What is the deal?

% ruby-1.8.2 -e 'def initialize @msg'
-e:1: formal argument cannot be an instance variable
-e:1: syntax error

Check the line endings.

--
eban