Wednesday, 14 August 2013

Ruby methods returning results in repl.it but not when I run the program

Ruby methods returning results in repl.it but not when I run the program

I'm very new to ruby and I have been writing some simple programs. I've
noticed that alot of my programs are creating no returned values when I
try to run them through the command line, but seem to be working perfectly
when I use repl.it for testing. For example:
def rev(a)
b = []
c = []
b = a.scan(/\w+/)
c = b.map {|x| x.reverse }
return c.join(' ')
end
rev('hello')
If I use puts c.join(' ') the answer will appear but it's not being
returned which is what I need to happen. I have a feeling this is
something very simple. Any help is appreciated, I've had to create some
weird and blocky work arounds to make my other programs work but have
limited what I've been able to do.

No comments:

Post a Comment