Skip to content

Instantly share code, notes, and snippets.

@cupakromer
Created November 14, 2012 01:28
Show Gist options
  • Save cupakromer/4069649 to your computer and use it in GitHub Desktop.
Save cupakromer/4069649 to your computer and use it in GitHub Desktop.
Pry Session Dump
class Test < SimpleDelegator
def initialize
end
end
#=> nil
t = Test.new
#=> nil
t[:thing] = 'help'
#=> NoMethodError: undefined method `[]=' for nil:Test
class Test
def initialize
@galaxy = {}
super @galaxy
end
end
#=> nil
t = Test.new
#=> {}
t[:thing] = 'help'
#=> "help"
t
#=> {:thing=>"help"}
class Test
def initialize
@galaxy = {}
end
def []=(sym, value)
@galaxy[sym] = value
end
end
#=> nil
t = Test.new
#=> nil
t[:thing] = 'help'
#=> "help"
t
#=> nil
class Test2
def initialize
@galaxy = {}
end
def method_missing(*args, &block)
@galaxy.send args, &block
end
end
#=> nil
t = Test2.new
#=> #<Test2:0x007fa3bd04b448 @galaxy={}>
t[:thing] = 'help'
#=> TypeError: [:[]=, :thing, "help"] is not a symbol
#=> from (pry):33:in `method_missing'
class Test2
def method_missing(sym, *args, &block)
@galaxy.send sym, args, &block
end
end
#=> nil
t = Test2.new
#=> #<Test2:0x007fa3bc85f220 @galaxy={}>
t[:thing] = 'help'
#=> ArgumentError: wrong number of arguments(1 for 2)
#=> from (pry):40:in `[]='
class Test2
def method_missing(sym, *args, &block)
@galaxy.send sym, *args, &block
end
end
#=> nil
t = Test2.new
#=> #<Test2:0x007fa3bb8f0618 @galaxy={}>
t[:thing] = 'help'
#=> "help"
t
#=> #<Test2:0x007fa3bb8f0618 @galaxy={:thing=>"help"}>
t.to_s
#=> "#<Test2:0x007fa3bb8f0618>"
t.path
#=> NoMethodError: undefined method `path' for {:thing=>"help"}:Hash
#=> from (pry):47:in `method_missing'
class Test
extend Forwardable
def_delegators :@galaxy, :[]=
def initialize
@galaxy = {}
end
end
#=> nil
t = Test.new
#=> #<Test:0x007fefcb882ad0 @galaxy={}>
t[:thing] = 'test'
#=> "test"
t
#=> #<Test:0x007fefcb882ad0 @galaxy={:thing=>"test"}>
t.path
#=> NoMethodError: undefined method `path' for #<Test:0x007fefcb882ad0 @galaxy={:thing=>"test"}>
class Test
def_delegators :@name, :to_s
def initialize
@galaxy = {}
@name = 'tester'
end
end
#=> [:to_s]
t = Test.new
#=> tester
t.to_s
#=> "tester"
t[:thing] = 'test'
#=> "test"
t
#=> tester
t.inspect
#=> "tester"
class Test
attr_reader :galaxy
end
#=> nil
t.galaxy
#=> {:thing=>"test"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment