Skip to content

Instantly share code, notes, and snippets.

View kachick's full-sized avatar
😋
😪

Kenichi Kamiya kachick

😋
😪
View GitHub Profile
@kachick
kachick / call_superclass_method.rb
Last active December 23, 2015 14:59
superclass(ancestor)のメソッドを再定義している時に、どの定義を使うか指定する
$VERBOSE = true
class Super
def a
"super_a"
end
def b
"super_b" + c
end
behavior :array_uniq_on_dupulicated_elements, :shared => true do
it "returns a squashed array" do
verify([1, 1].send(@method)).is.eq([1])
end
end
describe "Array#uniq" do
context "when elements are duplicated" do
verify.behavior(:array_uniq_on_dupulicated_elements, :uniq)
describe "Foo" do
context "Bar" do
it "Baz" do
end
end
end
#=> "Foo Bar Baz"
describe "Foo" do
@kachick
kachick / lookup_const.rb
Created September 2, 2013 11:31
定数の参照 - 前にruby-listへ投稿したけど特に反応が得られなかったもの http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/48791
$VERBOSE = true
class Super
class << self
CONS = :Singleton
end
CONS = :Super
end
@kachick
kachick / list.rst
Last active December 22, 2015 01:38
パーフェクトRuby(初版・第一刷)の正誤表が無いっぽいので、とりあえず流し読みして気づいた限りをまとめてみた。

My 正誤表 - パーフェクトRuby(初版・第一刷)

そのうち、 サポートページ_ とかに正式なの出来るのかもしれませんけど、2013/8/31時点では見当たら無かったので。

136 is_a? -> instance_of?

@kachick
kachick / integer-pred.rb
Created August 15, 2013 05:51
Integer#pred from Haskell
class Integer
def pred
self - 1
end
end
1.pred #=> 0
0.pred #=> -1
@kachick
kachick / array-init.rb
Created August 15, 2013 03:43
Array#init from Haskell
class Array
def init
self[0..-2]
end
end
[1, 3, 7].init #=> [1, 3]
@kachick
kachick / 0.README.md
Last active December 20, 2015 22:29
Class.allocate.new crashed on rbx

rubinius 2.0.0.n224 (1.9.3 e91782d0 2013-08-12 JI) [x86_64-unknown-linux-gnu]

Class.allocate.allocate #=> pass
Class.allocate.new #=> crash
Class.allocate.allocate.send(:initialize) #=> crash
# find_longest_api_name
# 2013 Kenichi Kamiya
# ruby -v: ruby 2.1.0dev (2013-08-10 trunk 42476) [x86_64-linux]
$VERBOSE = true
class BasicObject
def longest_method_name
(methods(true) | private_methods(true)).reject { |name|
/\Alongest_(?:instance_)?method_name\z/ =~ name }.max_by(&:length)
@kachick
kachick / taint-object_model.rb
Last active December 20, 2015 20:59
taint with singleton_class, Class, Module
RUBY_DESCRIPTION #=> "ruby 2.1.0dev (2013-08-09 trunk 42473) [x86_64-linux]
$VERBOSE = true
obj = Object.new
mod = Module.new.taint
obj.taint.singleton_class.tainted? #=> true
obj2 = Object.new