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


書籍 Ruby Cookbook | Predicate Method

パンくず

Ruby Cookbook
Predicate Method

概要

Predicate Method

Predicate Method

Predicate Method=述語メソッド

Rubyでは真偽値を返すメソッド=述語メソッドは末尾に?をつけます

サンプル

puts "".empty? # => true
puts "hoge".empty? # => false

# 自作クラスにPredicate Methodを実装
class Hoge
  attr_accessor:hoge
  def initialize(hoge);@hoge=hoge;end
  def hoge?;@hoge=="hoge";end
end

hoge = Hoge.new("hoge")
puts Hoge.new("hoge").hoge? # => true
puts Hoge.new("hige").hoge? # => false

出力

true
false
true
false



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

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