Module: Celluloid::Internals::Properties

### Home Classes Methods

### In Files

- lib/celluloid/internals/properties.rb

### Methods

- #property

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::Incident
- Celluloid::IncidentLogger
- Celluloid::IncidentLogger::Severity
- Celluloid::IncidentReporter
- Celluloid::IncidentReporter::Formatter
- Celluloid::Internals
- Celluloid::Internals::CPUCounter
- Celluloid::Internals::CallChain
- Celluloid::Internals::Handler
- Celluloid::Internals::Handlers
- Celluloid::Internals::Links
- Celluloid::Internals::Logger
- Celluloid::Internals::Logger::WithBacktrace
- Celluloid::Internals::Method
- Celluloid::Internals::Properties
- Celluloid::Internals::Receiver
- Celluloid::Internals::Receivers
- Celluloid::Internals::Registry
- Celluloid::Internals::Response
- Celluloid::Internals::Response::Block
- Celluloid::Internals::Response::Error
- Celluloid::Internals::Response::Success
- Celluloid::Internals::Signals
- Celluloid::Internals::Stack
- Celluloid::Internals::Stack::ActorState
- Celluloid::Internals::Stack::CellState
- Celluloid::Internals::Stack::DisplayBacktrace
- Celluloid::Internals::Stack::Dump
- Celluloid::Internals::Stack::Summary
- Celluloid::Internals::Stack::TaskState
- Celluloid::Internals::Stack::ThreadState
- Celluloid::Internals::TaskSet
- Celluloid::Internals::ThreadHandle
- Celluloid::Internals::UUID
- Celluloid::LogEvent
- Celluloid::Notifications
- Celluloid::Notifications::Fanout
- Celluloid::Notifications::Subscriber
- Celluloid::Probe
- Celluloid::RingBuffer

No matching classes.

# Celluloid::Internals::Properties

Properties define inheritable attributes of classes, somewhat similar to Rails cattr_*/mattr_* or class_attribute

### Public Instance Methods

property(name, opts = {}) click to toggle source

    # File lib/celluloid/internals/properties.rb, line 6
    def property(name, opts = {})
      default   = opts.fetch(:default, nil)
      multi     = opts.fetch(:multi, false)
      ivar_name = "@#{name}".to_sym

      singleton = class << ancestors.first; self; end
      singleton.send(:remove_method, name) rescue nil
      singleton.send(:define_method, name) do |value = nil, *extra|
        if value
          value = value ? [value, *send(name), *extra].uniq : [] 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.