Skip to content

Instantly share code, notes, and snippets.

@scalone
Created June 15, 2015 01:04
Show Gist options
  • Save scalone/c1b028d24c5cbd53c56a to your computer and use it in GitHub Desktop.
Save scalone/c1b028d24c5cbd53c56a to your computer and use it in GitHub Desktop.
module VersionFlat043
BLOCK = Proc.new do
class IO
def self.a; puts "Device Included Class a"; end
def b; puts "Device Included Instance b"; end
end
end
def self.flat klass
klass.class_eval &BLOCK
end
end
module Device
API_VERSION="0.4.3"
VERSION="0.4.3"
IO = ::IO
class IO
def self.a; puts "Device Class a"; end
def b; puts "Device Instance b"; end
end
class Network
def self.init; puts "Device Network init"; end
def self.finish; puts "Device Network finish"; end
end
def self.flat_api
klass_version = self::VERSION.gsub(".", "")
if self::VERSION == "0.4.3"
puts "#{self.name}"
const_get("VersionFlat#{klass_version}").flat self
end
end
end
class Network
def self.init; puts "PAX Network"; end
end
class PAX < Device
VERSION="0.4.4"
Network = Class.new(::Network, Device::) do
def self.init; puts "PAX Network"; end
end
#class Network < Device::Network
#def self.init; puts "PAX Network"; end
#end
class IO < Device::IO
def self.a; puts "PAX Class a"; end
end
flat_api
end
OldDevice = Device
Device = PAX
puts OldDevice.object_id
puts Device.object_id
puts PAX.object_id
puts Device
OldDevice::IO.a
Device::IO.a
Device::IO.new(1).b
Device::Network.init
Device::Network.finish
p Device::IO.ancestors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment