Module: AppInfo::Helper::GenerateClass
- Included in:
- Protobuf::Base, Protobuf::Resources::Entry, Protobuf::Resources::Package
- Defined in:
- lib/app_info/helper/generate_class.rb
Instance Method Summary collapse
- #create_class(klass_name, parent_class, namespace:) ⇒ Object
- #define_instance_method(key, value) ⇒ Object
Instance Method Details
#create_class(klass_name, parent_class, namespace:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/app_info/helper/generate_class.rb', line 5 def create_class(klass_name, parent_class, namespace:) klass = Class.new(parent_class) do yield if block_given? end name = namespace.to_s.empty? ? klass_name : "#{namespace}::#{klass_name}" if Object.const_get(namespace).const_defined?(klass_name) Object.const_get(namespace).const_get(klass_name) elsif Object.const_defined?(name) Object.const_get(name) else Object.const_get(namespace).const_set(klass_name, klass) end end |
#define_instance_method(key, value) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/app_info/helper/generate_class.rb', line 20 def define_instance_method(key, value) instance_variable_set("@#{key}", value) self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{key} @#{key} end RUBY end |