class Bar < Foo def awesome_method(keyword: "bar") super end end Bar.new.awesome_method # => go # Keyword arguments are not automatically passed to super
end # Standard pattern: reopen the class and alias_method_chain class Foo def bar_with_baz puts "baz" bar_without_baz end alias_method :bar_without_baz, :bar alias_method :bar, :bar_with_baz end Foo.new.bar # baz # bar
end end class Foo prepend Baz def bar puts "bar" end end # Or class_eval since prepend is private Foo.class_eval { prepend Baz } Foo.new.bar # baz # bar
end end end # Pretend this is in bar.rb require "foo" # Refinements currently have file scope using Foo class Bar def foo "".hello end end puts Bar.new.foo # => "world"
expensive: fork do 1 + 1 end # Ruby deployment is typically done with multiple processes. When each process # takes a big chunk of memory it's common to see: # Copy on Write makes fork calls cheaper because memory is only copied when it # is changed. # If one process takes 200Mb then 10 processes means 2Gb # Copy-on-Write can reduce that footprint significantly for subprocesses. Copy-on-Write (COW)