Ruby/Method/def

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

def and end define the welcome method:

def welcome
  puts "Welcome to Ruby methods."
end
welcome



define your own method with def/end

def hello
  puts "Hello, Matz!"
end
hello # => Hello, Matz!



Use def to define a function

def dog_barking
  puts "Woof!"
end
dog_barking