Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
module Wrapped
# This is the wrapper class
class Wrapper
attr_accessor :content
def initialize(content)
@content = content
end
def content_value
@content.value
end
end
# So that module can be inluded as well as extended
def self.included(base)
base.extend self
end
def new(*args)
Wrapper.new(super)
end
end
class Content
include Wrapped
attr_accessor :value
def initialize(default)
@value = default
end
end
class ComplicatedContent < Content
alias_method :simple_value, :value
def value
simple_value.reverse
end
end
c = Content.new("a_to_z")
puts "Content.new(\"a_to_z\"):"
puts "- class = #{c.class}"
puts "- value = #{c.content_value}"
c = ComplicatedContent.new("a_to_z")
puts "ComplicatedContent.new(\"a_to_z\"):"
puts "- class = #{c.class}"
puts "- value = #{c.content_value}"
class Wrapper
attr_accessor :content
def initialize(content)
@content = content
end
def content_value
@content.value
end
end
class Content
attr_accessor :value
class << self
def new(*args)
Wrapper.new(super)
end
end
def initialize(default)
@value = default
end
end
class ComplicatedContent < Content
alias_method :simple_value, :value
def value
simple_value.reverse
end
end
c = Content.new("a_to_z")
puts "Content.new(\"a_to_z\"):"
puts "- class = #{c.class}"
puts "- value = #{c.content_value}"
c = ComplicatedContent.new("a_to_z")
puts "ComplicatedContent.new(\"a_to_z\"):"
puts "- class = #{c.class}"
puts "- value = #{c.content_value}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.