ライブラリ
- ビルトイン (277)
- csv (132)
- delegate (12)
- erb (24)
- json (12)
-
json
/ add / exception (12) -
minitest
/ unit (1) -
net
/ http (24) - optparse (84)
- rake (696)
-
rake
/ loaders / makefile (12) -
rake
/ packagetask (24) -
rake
/ testtask (12) - shell (12)
-
shell
/ command-processor (12) -
shell
/ filter (12) - strscan (96)
- tracer (24)
クラス
- CSV (132)
- Dir (12)
- ERB (24)
- Exception (44)
- File (24)
- IO (56)
- Method (12)
- Module (12)
-
Net
:: HTTPGenericRequest (24) - OptionParser (84)
-
Rake
:: Application (84) -
Rake
:: FileList (216) -
Rake
:: FileTask (24) -
Rake
:: InvocationChain (60) -
Rake
:: MakefileLoader (12) -
Rake
:: NameSpace (12) -
Rake
:: PackageTask (24) -
Rake
:: TaskArguments (72) - Shell (12)
-
Shell
:: CommandProcessor (12) -
Shell
:: Filter (12) - StringScanner (84)
- TracePoint (24)
- Tracer (24)
モジュール
- JSON (12)
- Kernel (105)
-
MiniTest
:: Assertions (1) - Rake (36)
-
Rake
:: Cloneable (24) -
Rake
:: TaskManager (156)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - << (12)
- == (12)
-
NEWS for Ruby 2
. 2 . 0 (11) -
NEWS for Ruby 2
. 7 . 0 (6) -
NEWS for Ruby 3
. 0 . 0 (5) -
NEWS for Ruby 3
. 1 . 0 (4) - Proc (12)
- Rubyの起動 (4)
- Ruby用語集 (12)
- SimpleDelegator (12)
- StringScanner (12)
- TestTask (12)
- [] (42)
-
add
_ row (12) - append (24)
- application (12)
- application= (12)
-
assert
_ send (1) -
backtrace
_ locations (12) -
body
_ stream (12) -
body
_ stream= (12) -
caller
_ locations (24) - clear (12)
-
clear
_ exclude (12) - clone (24)
-
const
_ source _ location (12) -
create
_ rule (12) -
current
_ scope (12) -
def
_ class (12) -
def
_ module (12) -
define
_ task (12) - delete (12)
- desc (12)
- dump (12)
- dup (24)
- egrep (12)
-
excluded
_ from _ list? (12) - existing (12)
- existing! (12)
- ext (12)
- fdatasync (12)
- filter (36)
- flush (12)
- gsub! (12)
- import (12)
-
in
_ namespace (12) - inspect (18)
- intern (12)
-
is
_ a? (12) -
kind
_ of? (12) - lambda (18)
-
last
_ comment (12) -
last
_ description (12) -
last
_ description= (12) - load (12)
- lookup (12)
- match? (12)
-
matched
_ size (12) - member? (12)
-
minitest
/ unit (1) - name (12)
- names (12)
- needed? (12)
-
net
/ smtp (12) - new (60)
-
new
_ scope (12) - on (24)
-
on
_ head (12) -
on
_ tail (12) - open (48)
-
original
_ dir (24) -
package
_ files (12) -
package
_ files= (12) - parse (24)
- parse! (12)
- path (12)
- pathmap (12)
- peek (12)
- peep (12)
- pointer= (12)
- pos= (12)
- proc (19)
-
program
_ name= (12) - puts (12)
- rake (12)
- rakefile (12)
- read (12)
- resolve (12)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 2 feature (12) -
ruby 1
. 8 . 3 feature (12) -
ruby 1
. 8 . 4 feature (12) -
set
_ backtrace (12) - shell (6)
- sub! (12)
-
synthesize
_ file _ task (12) - tasks (12)
-
test
/ unit (1) -
to
_ a (24) -
to
_ ary (12) -
to
_ hash (12) -
to
_ json (12) -
to
_ s (30) -
top
_ level (12) -
top
_ level _ tasks (12) -
tty
_ output= (12) - unlink (12)
- unscan (12)
- warn (8)
-
with
_ defaults (12) - write (8)
- yaml (12)
-
yaml
/ store (12) - クラス/メソッドの定義 (12)
- プログラム・文・式 (12)
- リテラル (12)
- 手続きオブジェクトの挙動の詳細 (12)
- 演算子式 (12)
検索結果
先頭5件
-
クラス/メソッドの定義 (576.0)
-
クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined
...* defined
===[a:class] クラス定義
//emlist[例][ruby]{
class Foo < Super
def test
# ...
end
# ...
end
//}
文法:
class 識別子 [`<' superclass ]
式..
end
文法:
class 識別子 [`<' superclass ]
式..
[resc......ue [error_type,..] [=> evar] [then]
式..]..
[else
式..]
[ensure
式..]
end
クラスを定義します。クラス名はアルファベットの大文字で始まる識別子です。
rescue/ensure 節を指定し、例外処理....../emlist[][ruby]{
class Foo < Array
def foo
end
end
# 定義を追加(スーパークラス Array を明示的に指定しても同じ)
class Foo
def bar
end
end
# 間違ったスーパークラスを指定するとエラー
class Foo < String
end
# => superclass mismatch for class Foo (Typ... -
ruby 1
. 6 feature (330.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...ーになっていました。
((<ruby-dev:17155>))
open("|-","r+") {|f|
if f
f.dup.close_write
else
sleep 1
end
}
=> ruby 1.6.7 (2002-03-01) [i586-linux]
-:3:in `close_write': closing non-duplex IO for writing (IOError)
from -:3......トで 2 回シグナルを送らないと終了しない不具合が修正さ
れました。((<ruby-bugs-ja:PR#223>))
trap(:TERM, "EXIT")
END{
puts "exit"
}
Thread.start { Thread.stop }
sleep
: 2002-04-17: Regexp#inspect
((<ruby-bugs-ja:PR#222>))
p %r{\/}......: 2002-03-08 class variable
((<ruby-talk:35122>))
class C
class << self
def test
@@cv = 5
p @@cv
end
end
test
end
=> -:5:in `test': uninitialized class variable @@cv in C (NameError)
from -:9
ruby 1.6.7 (2002... -
ruby 1
. 8 . 4 feature (294.0) -
ruby 1.8.4 feature ruby 1.8.4 での ruby 1.8.3 からの変更点です。
...ruby 1.8.4 feature/printf [bug]>))
* ((<ruby 1.8.4 feature/Hash [bug]>))
* ((<ruby 1.8.4 feature/test [bug]>))
* ((<ruby 1.8.4 feature/File.identical? [new]>))
* ((<ruby 1.8.4 feature/FileTest.identical? [new]>))
* ((<ruby 1.8.4 feature/File.split [change]>))
* ((<ruby 1.8.4 feature/File......strictly. [ruby-dev:27478]
#
# * test/ruby/test_symbol.rb: tests for [ruby-core:03573].
Symbolに適合する文字列を厳密にした。((<ruby-core:03573>)),((<ruby-dev:27478>))
1) alias :"foo" :"bar"
def bar; p "bar"; end
alias :"foo" :"bar"......"$- "
2631438
# => ruby 1.8.4 (2005-12-22) [i686-linux]
-:2: syntax error, unexpected '(', expecting $end
#Tue Nov 1 14:20:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
#
# * eval.c (rb_call_super): should call method_missing if super is
#... -
NEWS for Ruby 2
. 7 . 0 (252.0) -
NEWS for Ruby 2.7.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...p b #=> 1
p c #=> [2, 3]
end
//}
//emlist[][ruby]{
case {a: 0, b: 1}
in {a: 0, x: 1}
:unreachable
in {a: 0, b: var}
p var #=> 1
end
//}
//emlist[][ruby]{
case -1
in 0 then :unreachable
in 1 then :unreachable
end #=> NoMatchingPatternError
//}
//emlist{
json = <<END
{
"name": "Alice",
"a......ge": 30,
"children": [{ "name": "Bob", "age": 2 }]
}
END
JSON.parse(json, symbolize_names: true) in {name: "Alice", children: [{name: name, age: age}]}
p name #=> "Bob"
p age #=> 2
JSON.parse(json, symbolize_names: true) in {name: "Alice", children: [{name: "Charlie", age: age}]}
#=> NoMatchin......16256
//emlist[test.rb][ruby]{
require "optparse"
OptionParser.new do |opts|
opts.on("-f", "--foo", "foo") {|v| }
opts.on("-b", "--bar", "bar") {|v| }
opts.on("-c", "--baz", "baz") {|v| }
end.parse!
//}
//emlist{
$ ruby test.rb --baa
Traceback (most recent call last):
test.rb:7:in `<main>':... -
Kernel
. # caller _ locations(range) -> [Thread :: Backtrace :: Location] | nil (168.0) -
現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。
...][ruby]{
def test1(start, length)
locations = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
end
def test2(start, length)
test1(start, length)
end
def test3(start, length)
test2(start, length)
end
caller_locations # => []
test3(1, nil)
#....../Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb:17:in `<main>'"]
# => [9, 13, 17]
# => ["/Users/user/test.rb", "/Users/user/test.rb", "/Users/user/test.rb"]
test3(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'"]
# => [9......, 13]
# => ["/Users/user/test.rb", "/Users/user/test.rb"]
test3(2, 1)
# => ["/Users/user/test.rb:13:in `test3'"]
# => [13]
# => ["/Users/user/test.rb"]
//}
@see Thread::Backtrace::Location, Kernel.#caller... -
Kernel
. # caller _ locations(start = 1 , length = nil) -> [Thread :: Backtrace :: Location] | nil (168.0) -
現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。
...][ruby]{
def test1(start, length)
locations = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
end
def test2(start, length)
test1(start, length)
end
def test3(start, length)
test2(start, length)
end
caller_locations # => []
test3(1, nil)
#....../Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb:17:in `<main>'"]
# => [9, 13, 17]
# => ["/Users/user/test.rb", "/Users/user/test.rb", "/Users/user/test.rb"]
test3(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'"]
# => [9......, 13]
# => ["/Users/user/test.rb", "/Users/user/test.rb"]
test3(2, 1)
# => ["/Users/user/test.rb:13:in `test3'"]
# => [13]
# => ["/Users/user/test.rb"]
//}
@see Thread::Backtrace::Location, Kernel.#caller... -
Rake
:: FileList # import(array) -> self (132.0) -
与えられた配列を自身にインポートします。
...る
IO.write("test1.rb", "test")
IO.write("test2.rb", "test")
task default: :test_rake_app
task :test_rake_app do
file_list = FileList.new("test1.rb", "test2.rb", "test3.rb")
file_list.import(["test4.rb", "test5.rb"]) # => ["test4.rb", "test5.rb", "test1.rb", "test2.rb", "test3.rb"]
file_lis......t # => ["test4.rb", "test5.rb", "test1.rb", "test2.rb", "test3.rb"]
end
//}... -
演算子式 (120.0)
-
演算子式 * assign * selfassign * multiassign * range * range_cond * and * or * not * cond
...出しに変換されます。
//emlist[例][ruby]{
class C
def initialize
@ary = [0,1,2,3,4,5,6,7]
end
def [](i)
@ary[i * 2]
end
def []=( i, v )
@ary[i * 2] = v
end
end
c = C.new
p c[3] # c.[]( 3 ) に変換され、その結果は 6
p c[3] = 1 # c.[]=(3,1) に変換......C
def foo
@foo
end
def foo=( v )
@foo = v
end
end
c = C.new
c.foo = 5 # c.foo=( 5 ) のように変換される
p c.foo # => 5
//}
属性は Module#attr を使って同じように定義できます。
//emlist[例][ruby]{
class C
attr :foo, true
end
c = C.new
c.foo = 5......2)...(n==3)
p n
end
}
#=> 2
# 3
# 「..」と「...」の違いを示すためだけの例
5.times{|n|
if (n==2)..(n==2)
p n
end
}
#=> 2
5.times{|n|
if (n==2)...(n==2)
p n
end
}
#=> 2
# 3
# 4
//}
===[a:and] and
//emlist[例][ruby]{
test && set
test and set
//}
文... -
Rake
:: FileList # gsub!(pattern , replace) -> self (96.0) -
自身に含まれるファイルリストのそれぞれのエントリに対して String#gsub を実行します。 自身を破壊的に変更します。
...rite("test1.rb", "test")
IO.write("test2.rb", "test")
task default: :test_rake_app
task :test_rake_app do
file_list = FileList.new("test1.rb", "test2.rb", "test3.rb")
file_list.gsub!(/\.rb/, ".erb") # => ["test1.erb", "test2.erb", "test3.erb"]
file_list # => ["test1.erb"......, "test2.erb", "test3.erb"]
end
//}... -
ruby 1
. 8 . 3 feature (96.0) -
ruby 1.8.3 feature *((<ruby 1.8 feature>)) *((<ruby 1.8.2 feature>))
...た。
$ cat mthd_taint.rb
th = Thread.new{
$SAFE = 3
class Hoge
def foo
puts "safe level: #{$SAFE}"
end
end
}
th.join
p $SAFE
Hoge.new.foo
$ ruby-1.8.2 mthd_taint.rb
0
"safe level: 0"
$ ruby-1.8.3 mthd_ta......るバグを修正しました。
$ cat r.rb
p /[\c\\]/ =~ "\c\\"
p /\c\\/ =~ "\c\\"
$ ruby-1.8.2 r.rb
r.rb:1: premature end of regular expression: /[\c\\]/
r.rb:2: invalid regular expression; '\' can't be last character: /\c\\/
$ ruby-1.8.3 r.rb
0
0
=......cat test_dlg.rb
foo = Object.new
foo2 = SimpleDelegator.new(foo)
def foo.bar
puts "bar"
end
foo2.bar
$ ruby-1.8.2 -r delegate test_dlg.rb
test_dlg.rb:6: undefined method `bar' for #<Object:0x4021b0a0> (NoMethodError)
$ ruby-1.8.3 -r delegate test_dl...