class Striuct

@abstract

Public Class Methods

adjustable?(object) click to toggle source

Return `true` if given object is sufficient as an adjuster role

# File lib/striuct/singleton_class.rb, line 42
def adjustable?(object)
  case object
  when Proc
    object.arity == 1
  else
    if object.respond_to?(:to_proc)
      object.to_proc.arity == 1
    else
      false
    end
  end
end
define(&block) click to toggle source

@yieldreturn [Class] (see Striuct.new) - reject floating class @return [void]

# File lib/striuct/singleton_class.rb, line 29
def define(&block)
  raise ArgumentError, 'block not supplied' unless block

  new(&block).tap { |subclass|
    subclass.class_eval {
      raise 'not yet finished' if @autonyms.empty?

      close
    }
  }
end
new(*autonyms, &block) click to toggle source

@param [Symbol, String] autonyms @yieldreturn [Class] @return [Class]

# File lib/striuct/singleton_class.rb, line 11
def new(*autonyms, &block)
  # warning for Ruby's Struct.new user
  first = autonyms.first
  if first.instance_of?(String) && /\A[A-Z]/ =~ first
    warn("no define constant first-arg(#{first}), the Struct behavior is not supported in Striuct")
  end

  Class.new(self) {
    autonyms.each do |autonym|
      add_member autonym
    end

    class_eval(&block) if block
  }
end
Also aliased as: new_instance
new_instance(*autonyms, &block)
Alias for: new

Private Class Methods

inherited(subclass) click to toggle source
Calls superclass method
# File lib/striuct/singleton_class.rb, line 57
def inherited(subclass)
  ret = super(subclass)

  subclass.class_eval {
    extend ClassMethods
    include Enumerable
    extend Eqq::Buildable
    include InstanceMethods

    _init
  }

  ret
end