문제

Hello I have the following simple piece of code

#! /usr/bin/ruby

input = gets.downcase.chomp.to_sym

send input

def abc

   puts "Hi"

end

When I run the script and type abc I get

test.rb:5:in `<main>': undefined method `abc' for main:Object (NoMethodError)

using ruby 1.9.1

도움이 되었습니까?

해결책

Try this please:

#! /usr/bin/ruby

def abc
  puts "Hi"
end

input = gets.downcase.chomp.to_sym
send input

Hope the code makes sense.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top