るりまサーチ

最速Rubyリファレンスマニュアル検索!
503件ヒット [1-100件を表示] (0.075秒)

別のキーワード

  1. openssl g
  2. openssl g=
  3. dh g
  4. dh g=
  5. dsa g=

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Bignum#<<(bits) -> Fixnum | Bignum (21215.0)

シフト演算子。bits だけビットを左にシフトします。

...シフト演算子。bits だけビットを左にシフトします。

@param bits シフトさせるビット数

printf("%#b\n", 0b0101 << 1) #=> 0b1010
p -1 << 1 #=> -2...

Integer#<<(bits) -> Integer (21215.0)

シフト演算子。bits だけビットを左にシフトします。

...シフト演算子。bits だけビットを左にシフトします。

@param bits シフトさせるビット数

//emlist[][ruby]{
printf("%#b\n", 0b0101 << 1) # => 0b1010
p -1 << 1 # => -2
//}...

String#<<(other) -> self (21115.0)

self に文字列 other を破壊的に連結します。 other が 整数である場合は other.chr(self.encoding) 相当の文字を末尾に追加します。

...her.chr(self.encoding) 相当の文字を末尾に追加します。

self を返します。

@param other 文字列もしくは 0 以上の整数

//emlist[例][ruby]{
str = "string"
str.concat "XXX"
p str # => "stringXXX"

str << "YYY"
p str # => "stringXXXYYY"

str << 65 # 文字AのAS...
...CIIコード
p str # => "stringXXXYYYA"
//}...

Fixnum#<<(bits) -> Fixnum | Bignum (18215.0)

シフト演算子。bits だけビットを左にシフトします。

...シフト演算子。bits だけビットを左にシフトします。

@param bits シフトさせるビット数

printf("%#b\n", 0b0101 << 1) #=> 0b1010
p -1 << 1 #=> -2...

Method#<<(callable) -> Proc (18133.0)

self と引数を合成した Proc を返します。

...ef f(x)
x * x
end

def g(x)
x + x
end

# (3 + 3) * (3 + 3)
p (method(:f) << method(:g)).call(3) # => 36
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('testfile', <<~TEXT)
Hello, World!...
...Hello, Ruby!
TEXT

pipeline = method(:pp) << WordScanner << File.method(:read)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}

@see Proc#<<, Proc#>>...

絞り込み条件を変える

Proc#<<(callable) -> Proc (18133.0)

self と引数を合成した Proc を返します。

...[ruby]{
f = proc { |x| x * x }
g
= proc { |x| x + x }

# (3 + 3) * (3 + 3)
p (f << g).call(3) # => 36
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('testfile', <<~TEXT)
Hello, World!
Hello...
..., Ruby!
TEXT

pipeline = proc { |data| puts "word count: #{data.size}" } << WordScanner << File.method(:read)
pipeline.call('testfile') # => word count: 4
//}

@see Method#<<, Method#>>...

String#gsub(pattern, replace) -> String (6133.0)

文字列中で pattern にマッチする部分全てを 文字列 replace で置き換えた文字列を生成して返します。

...列と置き換える文字列

//emlist[例][ruby]{
p 'abcdefg'.gsub(/def/, '!!') # => "abc!!g"
p 'abcabc'.gsub(/b/, '<<\&>>') # => "a<<b>>ca<<b>>c"
p 'xxbbxbb'.gsub(/x+(b+)/, 'X<<\1>>') # => "X<<bb>>X<<bb>>"
p '2.5'.gsub('.', ',') # => "2,5"
//}

注意:

第 2 引数 replace に...
...字列が評価される時点ではまだ正規表現マッチが行われておらず、
$1 がセットされていないからです。

また、gsub では「\」が部分文字列との置き換えという特別な意味を持つため、
replace に「\」自身を入れたいときは
「\...
...違い][ruby]{
p 'xbbb-xbbb'.gsub(/x(b+)/, "#{$1}") # => "-" # NG
p 'xbbb-xbbb'.gsub(/x(b+)/, "\1") # => "1-1" # NG
p 'xbbb-xbbb'.gsub(/x(b+)/, "\\1") # => "bbb-bbb" # OK
p 'xbbb-xbbb'.gsub(/x(b+)/, '\1') # => "bbb-bbb" # OK
p 'xbbb-xbbb'.gsub(/x(b+)/, '\\1') # => "...

Object#singleton_methods(inherited_too = true) -> [Symbol] (6121.0)

そのオブジェクトに対して定義されている特異メソッド名 (public あるいは protected メソッド) の一覧を返します。

...です。

singleton_methods(false) は、Object#methods(false) と同じです。

@param inherited_too 継承した特異メソッドを含める場合は真を、
そうでない場合は偽を指定します。

//emlist[例1][ruby]{
Parent = Class.new

class <<Parent
priv...
...)

class <<Foo
private; def private_class_foo() end
protected; def protected_class_foo() end
public; def public_class_foo() end
end

module Bar
private; def private_bar() end
protected; def protected_bar() end
public; def public_bar() end
end

obj = Foo.new
class <<obj
i...
...nd
public; def public_self() end
end

# あるオブジェクトの特異メソッドの一覧を得る。
p obj.singleton_methods(false)
p obj.methods(false)
p Foo.singleton_methods(false)

#実行結果

[:protected_self, :public_self]
[:protected_self, :public_self]
[:protected_class_foo,...

Integer#gcd(n) -> Integer (6115.0)

自身と整数 n の最大公約数を返します。

...大公約数を返します。

@raise ArgumentError n に整数以外のものを指定すると発生します。

//emlist[][ruby]{
2.gcd(2) # => 2
3.gcd(7) # => 1
3.gcd(-7) # => 1
((1<<31)-1).gcd((1<<61)-1) # => 1
//}

また、self や n...
...が 0 だった場合は、0 ではない方の整数の絶対値を返します。

//emlist[][ruby]{
3.gcd(0) # => 3
0.gcd(-7) # => 7
//}

@see Integer#lcm, Integer#gcdlcm...

Integer#gcdlcm(n) -> [Integer] (6115.0)

自身と整数 n の最大公約数と最小公倍数の配列 [self.gcd(n), self.lcm(n)] を返します。

...倍数の配列 [self.gcd(n), self.lcm(n)]
を返します。

@raise ArgumentError n に整数以外のものを指定すると発生します。

//emlist[][ruby]{
2.gcdlcm(2) # => [2, 2]
3.gcdlcm(-7) # => [1, 21]
((1<<31)-1).gcdlcm((1<<61)-1) # => [1, 4951760...
...154835678088235319297]
//}

@see Integer#gcd, Integer#lcm...

絞り込み条件を変える

String#gsub!(pattern, replace) -> self | nil (6115.0)

文字列中で pattern にマッチする部分全てを文字列 replace に破壊的に置き換えます。

...弧の内容に置き換えられます。
置換文字列内では \`、\'、\+ も使えます。
これらは $`、$'、$+ に対応します。

g
sub! は通常 self を変更して返しますが、
置換が起こらなかった場合は nil を返します。

@param pattern 置き換え...
...emlist[例][ruby]{
buf = "String-String"
buf.gsub!(/in./, "!!")
p buf # => "Str!!-Str!!"

buf = "String.String"
buf.gsub!(/in./, '<<\&>>')
p buf # => "Str<<ing>>-Str<<ing>>"
//}

注意:

引数 replace の中で $1 を使うことはできません。
replace は gsub メソッドの呼び出...
...しより先に評価されるので、
まだ gsub の正規表現マッチが行われておらず、
$1 がセットされていないからです。

また、gsub では「\」が部分文字列との置き換えという特別な意味を持つため、
replace に「\」自身を入れたい...

BasicObject#singleton_method_removed(name) -> object (6109.0)

特異メソッドが Module#remove_method に より削除された時にインタプリタから呼び出されます。

...def singleton_method_removed(name)
puts "singleton method \"#{name}\" was removed"
end
end

obj = Foo.new
def obj.foo
end

class << obj
remove_method :foo
end

#=> singleton method "foo" was removed
//}

@see Module#method_removed,BasicObject#singleton_method_added,BasicObject#singleton_me...
<< 1 2 3 ... > >>