1281件ヒット
[101-200件を表示]
(0.061秒)
クラス
-
ARGF
. class (99) - Array (77)
- BasicObject (55)
- Class (11)
- Data (4)
- Dir (11)
-
Encoding
:: Converter (22) -
Encoding
:: InvalidByteSequenceError (11) -
Encoding
:: UndefinedConversionError (11) - Enumerator (33)
-
Enumerator
:: Lazy (10) - File (11)
-
File
:: Stat (55) - Hash (11)
- IO (44)
- Integer (22)
- MatchData (11)
- Method (22)
- Module (90)
- Object (138)
- Proc (6)
- Range (6)
- Regexp (55)
-
RubyVM
:: AbstractSyntaxTree :: Node (6) -
RubyVM
:: InstructionSequence (66) - SignalException (11)
- String (110)
- Struct (22)
- Thread (36)
-
Thread
:: Backtrace :: Location (44) -
Thread
:: ConditionVariable (18) -
Thread
:: Queue (27) -
Thread
:: SizedQueue (27) - ThreadGroup (11)
- TracePoint (12)
- UnboundMethod (10)
モジュール
- Enumerable (66)
キーワード
- ! (11)
- != (11)
- << (6)
- === (28)
- =~ (11)
- [] (11)
-
absolute
_ path (22) - add (11)
-
alias
_ method (11) -
base
_ label (22) -
bind
_ call (10) - blockdev? (11)
- broadcast (9)
- chardev? (11)
-
const
_ added (2) - convert (11)
- cycle (44)
- deconstruct (2)
-
deconstruct
_ keys (2) - deq (18)
- disasm (11)
- disassemble (11)
- dump (11)
- each (88)
-
each
_ line (44) - empty? (11)
-
enum
_ for (22) - eof (11)
- eof? (11)
-
error
_ bytes (11) -
error
_ char (11) -
eval
_ script (6) - fetch (33)
- flock (11)
- gsub (44)
-
ignore
_ deadlock= (3) - inherited (11)
- initialize (11)
-
initialize
_ copy (11) -
insert
_ output (11) - inspect (39)
-
instruction
_ sequence (6) - label (11)
- match (22)
-
max
_ by (44) -
method
_ added (11) -
method
_ removed (11) -
method
_ undefined (11) - next (11)
- owner (11)
- path (11)
- pid (11)
- pop (18)
- prepend (11)
- prepended (11)
-
public
_ send (22) - read (11)
- refine (11)
-
respond
_ to? (11) - run (11)
- setgid? (11)
- setuid? (11)
- shift (18)
- signal (9)
- signm (11)
-
singleton
_ method _ added (11) -
singleton
_ method _ removed (11) -
singleton
_ method _ undefined (11) -
source
_ location (11) - sticky? (11)
- sub (33)
- taint (6)
- tap (11)
- times (22)
-
to
_ enum (22) -
to
_ s (22) -
undef
_ method (11) - upto (11)
- wakeup (11)
-
with
_ index (10) -
with
_ object (22) - ~ (11)
検索結果
先頭5件
-
String
# sub(pattern , replace) -> String (33.0) -
文字列中で pattern にマッチした最初の部分を 文字列 replace で置き換えた文字列を生成して返します。
...ックスラッシュを倍にするときによくある間違い][ruby]{
puts '\n'.sub(/\\/, "\\\\") # => \n # NG
puts '\n'.sub(/\\/, '\\\\') # => \n # NG
puts '\n'.sub(/\\/, "\\\\\\\\") # => \\n # OK
puts '\n'.sub(/\\/, '\\\\\\\\') # => \\n # OK
//}
このような間違いを......の可読性を上げるには、
\& や \1 よりも下記のようにブロック付き形式の sub を使うべきです。
//emlist[安全な例][ruby]{
p 'xbbb-xbbb'.sub(/x(b+)/) { $1 } # => "bbb-xbbb" # OK
puts '\n'.sub(/\\/) { '\\\\' } # => \\n # OK
//}
@see String#gsub... -
ThreadGroup
# add(thread) -> self (33.0) -
スレッド thread が属するグループを自身に変更します。
...uby]{
puts "Initial group is #{ThreadGroup::Default.list}"
# => Initial group is [#<Thread:0x4a49168 run>]
tg = ThreadGroup.new
t1 = Thread.new { sleep }
t2 = Thread.new { sleep }
puts "t1 is #{t1}" # => t1 is #<Thread:0x50bef60>
puts "t2 is #{t2}" # => t2 is #<Thread:0x50beed0>
tg.add(t1)
puts "In......itial group now #{ThreadGroup::Default.list}"
# => Initial group now [#<Thread:0x3039168 run>, #<Thread:0x50beed0 run>]
puts "tg group now #{tg.list}"
# => tg group now [#<Thread:0x50bef60 run>]
//}... -
Encoding
:: Converter # insert _ output(string) -> nil (27.0) -
変換器内のバッファに文字列を挿入します。 バッファに保持された文字列は、次の変換時の変換結果と一緒に返されます。
...}."
dst = ""
p ec.primitive_convert(src, dst) #=> :undefined_conversion
puts "[#{dst.dump}, #{src.dump}]" #=> ["HIRAGANA LETTER A is ", "."]
ec.insert_output("<err>")
p ec.primitive_convert(src, dst) #=> :finished
puts "[#{dst.dump}, #{src.dump}]" #=> ["HIRAGANA LETTER A is <err>.", ""]
e......st) #=> :undefined_conversion
puts "[#{dst.dump}, #{src.dump}]" #=> ["\e$B$O$!$H".force_encoding("ISO-2022-JP"), "\xE3\ x80\x82"]
ec.insert_output "?" # state change required to output "?".
p ec.primitive_convert(src, dst) #=> :finished
puts "[#{dst.dump}, #{src.dump}]"... -
MatchData
# inspect -> String (27.0) -
self の内容を人間に読みやすい文字列にして返します。
...て返します。
//emlist[例][ruby]{
puts /.$/.match("foo").inspect
# => #<MatchData "o">
puts /(.)(.)(.)/.match("foo").inspect
# => #<MatchData "foo" 1:"f" 2:"o" 3:"o">
puts /(.)(.)?(.)/.match("fo").inspect
# => #<MatchData "fo" 1:"f" 2:nil 3:"o">
puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("ho... -
Object
# ===(other) -> bool (27.0) -
case 式で使用されるメソッドです。d:spec/control#case も参照してください。
..."youth"
else
"adult"
end
puts result #=> "child"
def check arg
case arg
when /ruby(?!\s*on\s*rails)/i
"hit! #{arg}"
when String
"Instance of String class. But don't hit."
else
"unknown"
end
end
puts check([]) #=> unknown
puts check("mash-up in Ruby on Rails") #=......> instance of String class. But not hit...
puts check("<Ruby's world>") #=> hit! <Ruby's world>
//}
@see Object#==, Range#===, Module#===, Regexp#===, Enumerable#grep... -
Object
# tap {|x| . . . } -> self (27.0) -
self を引数としてブロックを評価し、self を返します。
...のメソッドの主目的です。
//emlist[][ruby]{
(1..10) .tap {|x| puts "original: #{x}" }
.to_a .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]{
(1..10) .tap {|x| puts "original: #{x}" }
.to_a .tap {|x| puts "array: #{x}" }
.select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
.map {|x| x*x } .tap {|x| puts "squares: #{x}" }
//}
@see Object#yield_self... -
BasicObject
# ! -> bool (21.0) -
オブジェクトを真偽値として評価し、その論理否定を返します。
...r = NegationRecorder.new
!recorder
!!!!!!!recorder
puts 'hoge' if !recorder
puts recorder.count #=> 3
//}
//emlist[例][ruby]{
class AnotherFalse < BasicObject
def !
true
end
end
another_false = AnotherFalse.new
# another_falseは*真*
puts "another false is a truth" if another_false
#=>... -
Data
# deconstruct -> array (21.0) -
self のメンバの値を配列で返します。
...ce
in n, 'km' # 裏側で #deconstruct を呼ぶ
puts "It is #{n} kilometers away"
else
puts "Don't know how to handle it"
end
# "It is 10 kilometers away" が表示される
# 以下のようにも書ける
case distance
in Measure(n, 'km')
puts "It is #{n} kilometers away"
# ...
end
//}
[... -
Data
# deconstruct _ keys(array _ of _ names _ or _ nil) -> hash (21.0) -
self のメンバの名前と値の組を Hash で返します。
...# 裏側で #deconstruct_keys を呼ぶ
puts "It is #{amount} kilometers away"
else
puts "Don't know how to handle it"
end
# "It is 10 kilometers away" が表示される
# 以下のようにも書ける
case distance
in Measure(amount:, unit: 'km')
puts "It is #{amount} kilometers away"
# ..... -
Module
# alias _ method(new , original) -> Symbol (21.0) -
メソッドの別名を定義します。
...メソッドの別名を定義します。
//emlist[例][ruby]{
module Kernel
alias_method :hoge, :puts # => :hoge
alias_method "foo", :puts # => :foo
end
//}
alias との違いは以下の通りです。
* メソッド名は String または Symbol で指定します
* グローバル......ます。
@param original 元のメソッド名。String または Symbol で指定します。
@return 作成したエイリアスのメソッド名を表す Symbol を返します。
@see d:spec/def#alias
//emlist[例][ruby]{
module Kernel
alias_method :foo, :puts
end
foo "bar" # bar
//}... -
Range
# ===(obj) -> bool (21.0) -
始端と終端の中に obj があるとき、true を返します。 そうでないとき、false を返します。
...//emlist[例][ruby]{
p (0...50) === 79 #=> false
p (60...80) === 79 #=> true
case 79
when 0...60 then puts "low"
when 60...80 then puts "medium" # => medium
when 80..100 then puts "high"
end
//}
2.5 以前は、単純に Range#include? メソッドを内部で呼んでいました。... -
Regexp
# ===(string) -> bool (21.0) -
文字列 string との正規表現マッチを行います。 マッチした場合は真を返します。
...ます。
@param string マッチ対象文字列
//emlist[例][ruby]{
a = "HELLO"
case a
when /\A[a-z]*\z/; puts "Lower case"
when /\A[A-Z]*\z/; puts "Upper case"
else; puts "Mixed case"
end
# => Upper case
/\A[a-z]*\z/ === "HELLO" # => false
/\A[A-Z]*\z/ === "HELLO" # => true
//}
@...