Skip to content

Instantly share code, notes, and snippets.

@shtirlic
Created November 12, 2012 02:43
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 shtirlic/4057224 to your computer and use it in GitHub Desktop.
Save shtirlic/4057224 to your computer and use it in GitHub Desktop.
[]
HELLO
hello
[{:upcase!=>"hello"}, {:downcase!=>"HELLO"}]
[Finished in 0.1s]
class StringWithLogs < String
attr_reader :story
def enable_story
@story = []
class << self
self.instance_methods.reject{|x| !x.to_s.include?('!')}.each do |m|
alias_method "old_#{m}".to_sym, m
define_method(m){|*args|@story << {m => dup} ;super(*args)}
end
end
end
end
p = StringWithLogs.new('hello')
p.enable_story
p p.story
puts p.upcase!
puts p.downcase!
p p.story
@nikitug
Copy link

nikitug commented Nov 12, 2012

Debugging masta! :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment