class Intercom::Lib::DynamicAccessorsOnMethodMissing
Attributes
arguments[R]
klass[R]
method_string[R]
method_sym[R]
object[R]
Public Class Methods
new(method_sym, *arguments, object)
click to toggle source
# File lib/intercom/lib/dynamic_accessors_on_method_missing.rb, line 7 def initialize(method_sym, *arguments, object) @method_sym = method_sym @method_string = method_sym.to_s @arguments = arguments @klass = object.class @object = object end
Public Instance Methods
define_accessors_or_call() { || ... }
click to toggle source
# File lib/intercom/lib/dynamic_accessors_on_method_missing.rb, line 15 def define_accessors_or_call(&block) return yield if not_an_accessor? if setter? Lib::DynamicAccessors.define_accessors(attribute_name, *arguments, object) object.send(method_sym, *arguments) else # getter if trying_to_access_private_variable? || trying_to_access_print_method? yield else raise Intercom::AttributeNotSetError, attribute_not_set_error_message end end end
Private Instance Methods
attribute_name()
click to toggle source
# File lib/intercom/lib/dynamic_accessors_on_method_missing.rb, line 39 def attribute_name method_string.gsub(/=$/, '') end
attribute_not_set_error_message()
click to toggle source
# File lib/intercom/lib/dynamic_accessors_on_method_missing.rb, line 51 def attribute_not_set_error_message "'#{method_string}' called on #{klass} but it has not been set an " + "attribute or does not exist as a method" end
not_an_accessor?()
click to toggle source
# File lib/intercom/lib/dynamic_accessors_on_method_missing.rb, line 31 def not_an_accessor? (method_string.end_with? '?') || (method_string.end_with? '!') || arguments.length > 1 end
setter?()
click to toggle source
# File lib/intercom/lib/dynamic_accessors_on_method_missing.rb, line 35 def setter? method_string.end_with? '=' end
trying_to_access_print_method?()
click to toggle source
# File lib/intercom/lib/dynamic_accessors_on_method_missing.rb, line 47 def trying_to_access_print_method? [:to_ary, :to_s].include? method_sym end
trying_to_access_private_variable?()
click to toggle source
# File lib/intercom/lib/dynamic_accessors_on_method_missing.rb, line 43 def trying_to_access_private_variable? object.instance_variable_defined?("@#{method_string}") end