我试图在rails控制台中编写一个函数,在本例中,这就是该函数在终端中的外观。
>> def string_message(str = '') >> return "It's an empty string!" if str.empty? >> return "The string is nonempty." >> end
>> def string_message(str = '') \n\t return "It's an empty string!" if str.empty? \n\t blah blah \n\t
?
IRB,ruby控制台,其中 rails console 它支持开箱即用。
rails console
只需键入函数声明,按enter键,然后逐行输入正文,最后键入 end .
end
您将看到如下文本:
2.4.1 :001 > def say_hi(person) 2.4.1 :002?> puts "Hi #{person}" 2.4.1 :003?> end => :say_hi 2.4.1 :004 > say_hi("Nina") Hi Nina => nil 2.4.1 :005 >