31件ヒット
[1-31件を表示]
(0.022秒)
ライブラリ
- ビルトイン (31)
キーワード
-
define
_ singleton _ method (12) - tap (4)
- then (1)
-
to
_ str (6) -
yield
_ self (2)
検索結果
先頭5件
-
Object
# to _ s -> String (18108.0) -
オブジェクトの文字列表現を返します。
...て文字列に変換し
ます。
class Foo
def initialize num
@num = num
end
end
it = Foo.new(40)
puts it #=> #<Foo:0x2b69110>
class Foo
def to_s
"Class:Foo Number:#{@num}"
end
end
puts it #=> Class:Foo Number:40
@see Object#to_str,Kernel.#String... -
Object
# to _ str -> String (6107.0) -
オブジェクトの String への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。
...。
デフォルトでは定義されていません。
説明のためここに記載してありますが、
このメソッドは実際には Object クラスには定義されていません。
必要に応じてサブクラスで定義すべきものです。
このメソッドを定義する......ての場面で代置可能であるような、
* 文字列そのものとみなせるようなもの
という厳しいものになっています。
class Foo
def to_str
'Edition'
end
end
it = Foo.new
p('Second' + it) #=> "SecondEdition"
@see Object#to_s,Kernel.#String... -
Object
# define _ singleton _ method(symbol) { . . . } -> Symbol (7.0) -
self に特異メソッド name を定義します。
...スタンスを指定します。
@return メソッド名を表す Symbol を返します。
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"... -
Object
# define _ singleton _ method(symbol , method) -> Symbol (7.0) -
self に特異メソッド name を定義します。
...スタンスを指定します。
@return メソッド名を表す Symbol を返します。
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"... -
Object
# tap {|x| . . . } -> self (7.0) -
self を引数としてブロックを評価し、self を返します。
....tap {|x| puts "array: #{x}" }
.select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
.map {|x| x*x } .tap {|x| puts "squares: #{x}" }
//emlist[例][ruby]{
"my string".yield_self {|s| s.upcase } # => "MY STRING"
3.next.yield_self {|x| x**x }.to_s # => "256"... -
Object
# then {|x| . . . } -> object (7.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...評価し、ブロックの結果を返します。
//emlist[例][ruby]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
@see Object#tap... -
Object
# yield _ self {|x| . . . } -> object (7.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...を返します。
//emlist[例][ruby]{
"my string".yield_self {|s| s.upcase } # => "MY STRING"
3.next.yield_self {|x| x**x }.to_s # => "256"
//}
@see Object#tap......評価し、ブロックの結果を返します。
//emlist[例][ruby]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
@see Object#tap...