We have a widget that we want to extend
class Widget
end
so we open it and define_method
class Widget
define_method :hello do
puts "Hello!"
| n.times { doc.add_text(msg) } | |
| n.times { doc.undo } | |
| n.times { doc.redo } |
| # modules work! :) If we define_method on a module and include it, it works the same. | |
| class A | |
| include World | |
| end | |
| module World | |
| def hello | |
| puts "World" | |
| end |
| 100000 Strings | |
| After Block: 3318 | |
| After Forced GC: 31 | |
| 100000 Symobls | |
| After Block: 1519 | |
| After Forced GC: 98619 |
| class Value | |
| attr_reader :value | |
| def initialize(value) | |
| @value = value | |
| end | |
| def add(i) | |
| class.self.new(i + @value) | |
| end | |
| end |
| require "json" | |
| file = ARGV[0] | |
| branches = File.open(file) {|f| JSON.parse(f.read).freeze } | |
| LABEL_STRING = '"%s" [label="%s"]' | |
| GRAPH_STRING = '"%s" -> "%s"' | |
| cells = [] | |
| puts "digraph graph_example {" |
We have a widget that we want to extend
class Widget
end
so we open it and define_method
class Widget
define_method :hello do
puts "Hello!"
| modules_to_load = [ | |
| Authlogic::ActsAsAuthentic::SingleAccessToken::Methods::InstanceMethods, | |
| Authlogic::ActsAsAuthentic::SingleAccessToken::Methods, | |
| Authlogic::ActsAsAuthentic::SessionMaintenance::Methods, | |
| Authlogic::ActsAsAuthentic::PersistenceToken::Methods::InstanceMethods, | |
| Authlogic::ActsAsAuthentic::PersistenceToken::Methods, | |
| Authlogic::ActsAsAuthentic::PerishableToken::Methods::InstanceMethods, | |
| Authlogic::ActsAsAuthentic::PerishableToken::Methods, | |
| Authlogic::ActsAsAuthentic::Password::Methods::InstanceMethods, | |
| Authlogic::ActsAsAuthentic::Password::Methods, |
| A=" on the wall" | |
| def z n | |
| "%s bottle#{"s" if n>1} of beer"%n | |
| end | |
| 99.downto(1){|n|a,b,c=n,*n>1?[n-1,"Take one down and pass it around"]:[99,"Go to the store and buy some more"] | |
| d=z a | |
| puts"%s, %s. | |
| "*2%[d+A,d,c,z(b)+A]+" | |
| "} |
| class CustomError < StandardError | |
| def initialize(message = nil) | |
| message ||= "Default message." | |
| super(message) | |
| end | |
| end |