Sha256: 6dfbc7572fb1220554e1f5467e8df420ff457e9c568431c5c175908e823dc968

Contents?: true

Size: 735 Bytes

Versions: 1

Compression:

Stored size: 735 Bytes

Contents

require 'naniyatsu/version'
require 'active_support/core_ext/string/inflections'

module Naniyatsu
  attr_reader :root_naniyatsu_class

  def self.extended(klass)
    klass.instance_variable_set :@root_naniyatsu_class, klass
    klass.send(:define_method, klass.naniyatsu_method_name(klass), -> { true })
  end

  def inherited(klass)
    root_naniyatsu_class = klass.superclass.root_naniyatsu_class
    klass.instance_variable_set :@root_naniyatsu_class, root_naniyatsu_class
    klass.send(:define_method, naniyatsu_method_name(klass), -> { true })
    root_naniyatsu_class.send(:define_method, naniyatsu_method_name(klass), -> { false })
    super
  end

  def naniyatsu_method_name(klass)
    klass.to_s.underscore + '?'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
naniyatsu-0.0.2 lib/naniyatsu.rb