以下の内容はhttps://tbpgr.hatenablog.com/entry/20120512/1336837653より取得しました。


Ruby | ブロック | 基礎

パンくず

Ruby
ブロック
基礎

概要

ブロックについて

内容

Rubyのブロックの基本的なパターンをサンプルとして例示します

構文

yieldによってブロック内のコードを呼び出すことが出来ます。

yield param...

サンプル

require "pp"

class Person
  attr_accessor:first_name,:family_name
  def initialize(first_name,family_name)
    @first_name = first_name
    @family_name = family_name
  end
end

def fullname(person)
  yield "#{person.first_name} #{person.family_name}"
end 

tanaka = Person.new("tanaka","yoshio")
fullname(tanaka){|fullname| puts fullname}

出力

tanaka yoshio



以上の内容はhttps://tbpgr.hatenablog.com/entry/20120512/1336837653より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14