What's difference?

K

Kyung won Cheon

--- test1.rb ---

b = 1
puts a if a = b

# NameError: undefined local variable or method `a' for main:Object


--- test2.rb ---

a = 1 if false
puts defined?(a)

# local-variable


###############
# Help Me^^
###############
 
M

Mikael Høilund

--- test1.rb ---

b =3D 1
puts a if a =3D b

# NameError: undefined local variable or method `a' for main:Object


Parser peculiarity. You can't use a local variable defined for the =20
first time in the clause of an inline-if for that statement. Define a =20=

before it reaches that line, or use this instead:

if a =3D b then puts a end

--=20
# Mikael H=F8ilund
def method_missing(m, a=3D0) a +
m.to_s[/[a-z]+/].size * 2; end
p What is the meaning of life?
 
P

psy

Hier from Programming Ruby book. Its not exactly for this case, but i think it gets close :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top