Sha256: 751e095d69b3ddcd080342167007b52312bee57c40438996942c2df8c3350d5d

Contents?: true

Size: 765 Bytes

Versions: 6

Compression:

Stored size: 765 Bytes

Contents

module Celluloid
  # Properties define inheritable attributes of classes, somewhat similar to
  # Rails cattr_*/mattr_* or class_attribute
  module Properties
    def property(name, opts = {})
      default   = opts.fetch(:default, nil)
      multi     = opts.fetch(:multi, false)
      ivar_name = "@#{name}".to_sym

      ancestors.first.send(:define_singleton_method, name) do |value = nil, *extra|
        if value
          value = value ? [value, *extra] : [] if multi
          instance_variable_set(ivar_name, value)
        elsif instance_variables.include?(ivar_name)
          instance_variable_get(ivar_name)
        elsif superclass.respond_to? name
          superclass.send(name)
        else
          default
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/properties.rb
celluloid-0.15.2 lib/celluloid/properties.rb
celluloid-0.15.1 lib/celluloid/properties.rb
celluloid-0.15.0 lib/celluloid/properties.rb
celluloid-0.15.0.pre2 lib/celluloid/properties.rb
celluloid-0.15.0.pre lib/celluloid/properties.rb