开发者

Recalling a method

I wrote a 开发者_Go百科program with three methods: def calculate, def compute, and def capture. Each method had some calculations in them. I want to get just the numeric answer of these methods and use them as a response to a question. I'm looking for it to say something like: Correct, 'calculate answer' and 'compute answer' and 'capture answer'. How would I do about doing this?


I'll take a stab at it. Do you mean something like this?

Example code:

def calculate a
  a + 4
end

def compute a
  a * 2
end

def capture a
  a - 5
end

def question a
  puts "Correct, 'calculate #{calculate a}' and 'compute #{compute a}' and 'capture #{capture a}'"
end

Which, in irb gives:

>> question 17
Correct, 'calculate 21' and 'compute 34' and 'capture 12'
=> nil
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜