Skip to content

Instantly share code, notes, and snippets.

@lsdr
Created August 21, 2009 19:56
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 lsdr/172388 to your computer and use it in GitHub Desktop.
Save lsdr/172388 to your computer and use it in GitHub Desktop.
Experimentations with Ruby's super
module Upstream
module Streamer
def self.included(receiver)
receiver.extend ExtensionMethods
end
module ExtensionMethods
def streamable!
self.send :include, InstanceMethods
end
end
module InstanceMethods
def index!
execute_on_index('index!')
end
protected
def execute_on_index(text)
"Streamer #{text.upcase}!"
end
def insert_on_index
execute_on_index('insert on index')
end
end
end
end
class Scopable
include Upstream::Streamer
streamable!
attr_accessor :scope
def index!
unless scope.nil?
execute_on_index('uh knoh')
else
super
end
end
protected
def insert_on_index
unless scope.nil?
execute_on_index('insert on uh knoh!')
else
super
end
end
end
s = Scopable.new
puts s.index!
puts s.send :insert_on_index
s.scope = :local
puts s.index!
puts s.send :insert_on_index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment