Class: FlexStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/flex_struct.rb,
lib/flex_struct/frozen.rb,
lib/flex_struct/version.rb,
lib/flex_struct/initializer.rb

Overview

A drop-in replacement for Struct which adds a more flexible initialize method

Defined Under Namespace

Modules: Frozen, Initializer

Constant Summary collapse

VERSION =
"0.1.2".freeze

Class Method Summary collapse

Class Method Details

.new(*args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/flex_struct.rb', line 7

def self.new(*args, &block)
  Struct.new(*args) do
    module_eval(&block) if block

    # Insert our `initialize` method into the ancestors chain so it can be
    # overridden by `block` if necessary
    include Initializer
  end
end