Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Gds
- module Props
- def self.included(base)
- base.extend ClassMethods
- end
- module ClassMethods
- def props(*args)
- @props ||= []
- @props += args
- args.each do |prop|
- class_eval %{
- def self.#{prop}(value)
- @#{prop} = value
- end
- }
- end
- @props
- end
- end
- end
- class Base
- include Props
- props :schema, :host
- def to_url
- # UGLY
- @schema = self.class.instance_variable_get(:@schema)
- @host = self.class.instance_variable_get(:@host)
- "#{@schema}://#{@host}"
- end
- end
- class Example < Base
- schema 'http'
- host 'localhost'
- end
- class Other < Base
- schema 'https'
- host 'google.com'
- end
- end
- e = Gds::Example.new
- puts "#{e.to_url}"
- e = Gds::Other.new
- puts "#{e.to_url}"
Add Comment
Please, Sign In to add comment