Module: Callable
- Extended by:
- ActiveSupport::Concern
- Included in:
- BuildFileOverlay, FileBuilder::Authorisation, FileBuilder::BuildStrongParams, FileBuilder::ClassDefinition, FileBuilder::ControllerAction, FileBuilder::SkipCsrf, FileBuilder::TrackEvent, FindMethodFromEvent::DisplayMethod, FindMethodFromEvent::FindMethod, FindMethodInPath::AddMethod, FindMethodInPath::DisplayMethod, FindMethodInPath::FindMethod, FindMethodInPath::Replace, GenerateBuffer, GenerateBuffer::FindMethod, GenerateBuffer::InitializeModuleClass, GenerateBuffer::Replace, GenerateBuffer::Url, SplitMethods::DisplayMethod, TestOne, UpdateCode::AddMethod, UpdateCode::FindMethod, UpdateCode::ReplaceCode, UpdateCode::ShowCode
- Defined in:
- app/services/callable.rb
Overview
def call
do some stuff in here
end
end
Instance Method Summary collapse
-
#initialize(kwargs) ⇒ Object
OVERRIDING VALUES IN INITIALIZE.
Instance Method Details
#initialize(kwargs) ⇒ Object
OVERRIDING VALUES IN INITIALIZE
If you want to override values in initialize then you can put this in your calling class and it will let you transform one of the values:
def initialize(args)
super
@quantity = args[:quantity].to_i
end
Its not super clean, but there might be times it needs to be done.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/services/callable.rb', line 109 def initialize(kwargs) # Set each of them as an instance var, i.e. # @something = something readable_attributes = self.class.readable_attributes(kwargs) readable_attributes.each do |key, value| instance_variable_set("@#{key}", value) end @context = Hashie::Mash.new(kwargs) # Then we set them as attr_readers so we can call them # i.e. something class_eval do private attr_reader(*readable_attributes.keys.map(&:to_sym)) attr_reader(:context) end end |