Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Created May 26, 2012 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ympbyc/16026b684b6406bcb92e to your computer and use it in GitHub Desktop.
Save ympbyc/16026b684b6406bcb92e to your computer and use it in GitHub Desktop.
Rubyをpasberthくんから教わったときのirbの履歴をペースト
def functionname a, b, c
a + b + c
end
functionname 1, 2, 3
class Array
def myeach &block
self.each &block
end
end
[1,2,3,4].myeach { |item| p item }
# bl = {|x| 1}
# SyntaxError: compile error
# (irb):21: syntax error, unexpected '|', expecting '}'
# bl = {|x| 1}
# ^
# (irb):21: syntax error, unexpected '}', expecting $end
# from (irb):21
# bl = lambda {|x| 1}
# => #<Proc:0x000000010901cb60@(irb):22>
bl = lambda {|x| 1}
bl.call 1
# => 1
bl.call 2
# => 1
module Ympbyc
class Pasberth
def mana
end
end
end
Ympbyc::Pasberth.new.mana
# => nil
class Pasberth
def initialize
@hoge = 1
end
def hoge= a
@hoge = a
end
def hoge
@hoge
end
end
a = Pasberth . new
a.hoge
# => 1
a.hoge = 2
# => 2
a.hoge
# => 2
class A
attr_accessor :hoge
end
a = A.new
a.hoge
# => nil
a.hoge = 2
# => 2
a.hoge
# => 2
{ 'a' => 1, 'b' => 2}
{ 'a' => 1, 'b' => 2}['a']
:a == :a
# => true
'a' == 'a'
# => true
'a'.__id__
# => 2223444280
'a'.__id__
# => 2223434640
'a'.equal? 'a'
# => false
:a.equal? :a
# => true
'a' == :a
# => false
def hoge
1
end
send :hoge
# => 1
send 'hoge'
# => 1
class Hoge
def method_missing mthdname, *args
case mthdname
when :fuga then p 1
end
end
end
# => nil
Hoge.new.fuga
# 1
# => nil
Hoge.new.hkjhlk
# => nil
class Hoge
def method_missing mthdname, *args
super
end
end
# => nil
# Hoge.new. hjakdlh
# NoMethodError: undefined method `hjakdlh' for #<Hoge:0x109018998>
# from (irb):131:in `method_missing'
# from (irb):134
# def method_missing mtdnm, *args
# if mtdnm == :hoge
# 1
# end
# end
# => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment