This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
true || y = 1 | |
p y # => nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: SJIS | |
class Hoge | |
def method_missing(m,*args) | |
p "called:" + m.to_s | |
super # call original exception | |
end | |
end | |
Hoge.new.no_method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: SJIS | |
class Hoge | |
def huga1; end | |
def huga2; end | |
alias :huga3 :huga1 | |
undef :huga2 | |
end | |
p Hoge.instance_methods(false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: SJIS | |
class Foo | |
def initialize(a) | |
@a = a | |
end | |
def method1 | |
@a | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: SJIS | |
p 1 | |
class Hoge | |
p 2 | |
end | |
p 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
def bar | |
catch(:calc) do | |
throw :calc , 100 | |
end | |
end | |
p bar | |
# => 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: SJIS | |
def foo | |
throw :exit | |
end | |
catch(:exit) { | |
foo | |
p 1 # Do not call | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: SJIS | |
begin | |
1/0 | |
rescue | |
p 1 | |
rescue ZeroDivisionError # Do not call | |
p 2 | |
end | |
# => 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: SJIS | |
a = 0 | |
begin | |
b = 1 / a | |
rescue ZeroDivisionError | |
a += 1 | |
retry | |
ensure | |
p b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: SJIS | |
begin | |
1/0 | |
rescue ZeroDivisionError | |
p $!.class # => ZeroDivisionError | |
raise # => ZeroDivisionError | |
end |