Module: Rolistic

Defined in:
lib/rolistic.rb,
lib/rolistic/version.rb,
lib/rolistic/everything.rb,
lib/rolistic/class_methods.rb

Defined Under Namespace

Modules: ClassMethods, Everything

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
9
10
11
# File 'lib/rolistic.rb', line 6

def self.included(klass)
  klass.class_exec do
    attr_reader :name, :abilities
    extend ClassMethods
  end
end

Instance Method Details

#can?(ability) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rolistic.rb', line 22

def can?(ability)
  abilities.member?(ability)
end

#default?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rolistic.rb', line 26

def default?
  name == self.class.default
end

#initialize(name = self.class.default) ⇒ Object



13
14
15
16
# File 'lib/rolistic.rb', line 13

def initialize(name = self.class.default)
  @name = name.to_sym if name
  @abilities = self.class.abilities_for(@name)
end

#inspectObject



30
31
32
# File 'lib/rolistic.rb', line 30

def inspect
  "#<#{self.class} :#{to_s}>"
end

#to_sObject



18
19
20
# File 'lib/rolistic.rb', line 18

def to_s
  name.to_s
end