class Module

Public Instance Methods

const_replace(name, value) click to toggle source
# File lib/r_kit/utility/module_extend.rb, line 67
def const_replace name, value
  remove_const name
  const_set name, value
end
namespace() click to toggle source
# File lib/r_kit/utility/module_extend.rb, line 6
def namespace
  (deconstantize.presence || 'Object').constantize
end
singleton_attr_reader(*args, **options) click to toggle source
# File lib/r_kit/utility/module_extend.rb, line 54
def singleton_attr_reader *args, **options
  singleton_class.send :attr_reader, *args, **options
end
tap_attr_accessor(*names, typecast: nil) click to toggle source

TODO: these writter are called like “.name(value)” to set and return self or like “.name” to read TODO: to be used in ‘pagination’, these need an “after” callback (to set @limited_collection to nil) TODO: and to be used in ‘grid (base.rb, binding_accessor)’, these need an “to” delegation object

# File lib/r_kit/utility/module_extend.rb, line 39
def tap_attr_accessor *names, typecast: nil
  names.each do |name|
    define_method name, ->(value = Nothing) do
      if value.thing?
        value = value.send typecast if typecast
        instance_variable_set "@#{ name }", value
        self
      else
        instance_variable_get "@#{ name }"
      end
    end
  end
end

Protected Instance Methods

depend(*args, strict: true, **options, &block) click to toggle source
# File lib/r_kit/override/module_extend.rb, line 39
          def depend *args, strict: true, **options, &block
  override_methods pattern: (strict && :depend || :if), pattern_args: (args << options), &block
end
override_method(method_name, method: nil, pattern: :standard, pattern_args: [], &block) click to toggle source
# File lib/r_kit/override/module_extend.rb, line 3
          def override_method method_name, method: nil, pattern: :standard, pattern_args: [], &block

  RKit::Override::Base.override method_name,
    method: (method || block),
    pattern: pattern,
    pattern_args: pattern_args,
    receiver: self

end
override_methods(**options, &block) click to toggle source
# File lib/r_kit/override/module_extend.rb, line 13
          def override_methods **options, &block

  carrier = Module.new(&block)

  carrier.instance_methods(false).each do |method_name|
    override_method method_name, method: carrier.instance_method(method_name), **options
  end

  carrier.methods(false).each do |method_name|
    singleton_carrier ||= Module.new{ include refine(carrier.singleton_class){} }
    override_singleton_method method_name, method: singleton_carrier.instance_method(method_name), **options
  end
end
override_singleton_method(*args, &block) click to toggle source
# File lib/r_kit/override/module_extend.rb, line 29
          def override_singleton_method *args, &block
  singleton_class.override_method *args, &block
end
override_singleton_methods(*args, &block) click to toggle source
# File lib/r_kit/override/module_extend.rb, line 33
          def override_singleton_methods *args, &block
  singleton_class.override_methods *args, &block
end
simple_override_method(method_name, &block) click to toggle source
# File lib/r_kit/override/module_extend.rb, line 45
          def simple_override_method method_name, &block
  instance_method(method_name).simple_override receiver: self, &block
end
simple_override_singleton_method(method_name, &block) click to toggle source
# File lib/r_kit/override/module_extend.rb, line 49
          def simple_override_singleton_method method_name, &block
  method(method_name).simple_override &block
end