Class: Fixnum

Inherits:
Object
  • Object
show all
Defined in:
lib/fixnum.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object

Matches any methods of the form dN, where N > 0, and calls #dX(N)



16
17
18
19
20
21
22
# File 'lib/fixnum.rb', line 16

def method_missing(symbol, *args, &block)
  if symbol =~ /^d(.*)$/ and $1.to_i > 0
    dX($1.to_i)
  else
    super
  end
end

Instance Method Details

#dFObject

Returns a pool of fudge dice of size self



11
12
13
# File 'lib/fixnum.rb', line 11

def dF
  Tabletop::Pool.new("#{self}dF")
end

#dX(sides) ⇒ Object

Returns a pool of dice of the given sides and size self



6
7
8
# File 'lib/fixnum.rb', line 6

def dX(sides)
  Tabletop::Pool.new("#{self}d#{sides}")
end

#respond_to?(symbol, include_private = false) ⇒ Boolean

Returns true for :dN, where N.to_i is a number > 0

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/fixnum.rb', line 25

def respond_to?(symbol, include_private = false)
  if symbol.to_s =~ /^d(.*)$/
    true if $1.to_i > 0
  else
    super
  end
end