Class: FBomb::Command::DSL
- Inherits:
-
Object
- Object
- FBomb::Command::DSL
- Defined in:
- lib/fbomb/command.rb
Overview
dsl
Class Method Summary collapse
Instance Method Summary collapse
- #call(&block) ⇒ Object
- #command(*args, &block) ⇒ Object (also: #Command)
- #evaluate(*args, &block) ⇒ Object
- #help(*args) ⇒ Object
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
- #match(*args, &block) ⇒ Object
- #matches(*args) ⇒ Object
- #setup(&block) ⇒ Object
Constructor Details
#initialize ⇒ DSL
Returns a new instance of DSL.
157 158 159 |
# File 'lib/fbomb/command.rb', line 157 def initialize @commands = Command.table end |
Class Method Details
.evaluate(*args, &block) ⇒ Object
151 152 153 154 155 |
# File 'lib/fbomb/command.rb', line 151 def DSL.evaluate(*args, &block) dsl = new dsl.evaluate(*args, &block) dsl end |
Instance Method Details
#call(&block) ⇒ Object
199 200 201 |
# File 'lib/fbomb/command.rb', line 199 def call(&block) @command.call = block end |
#command(*args, &block) ⇒ Object Also known as: Command
165 166 167 168 169 170 171 |
# File 'lib/fbomb/command.rb', line 165 def command(*args, &block) return @command if(args.empty? and block.nil?) @command = Command.new @command.key = Util.absolute_key_for(args.shift) @commands[@command.key] ||= @command evaluate(&block) end |
#evaluate(*args, &block) ⇒ Object
161 162 163 |
# File 'lib/fbomb/command.rb', line 161 def evaluate(*args, &block) Object.instance_method(:instance_eval).bind(self).call(&block) end |
#help(*args) ⇒ Object
191 192 193 |
# File 'lib/fbomb/command.rb', line 191 def help(*args) @command.help = args.join("\n") end |
#match(*args, &block) ⇒ Object
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/fbomb/command.rb', line 174 def match(*args, &block) return @command if(args.empty? and block.nil?) @command = Command.new pattern = args.shift key = Util.absolute_key_for(pattern.to_s) @command.key = key @command.patterns.push(pattern) @commands[@command.key] ||= @command evaluate(&block) end |
#matches(*args) ⇒ Object
185 186 187 188 189 |
# File 'lib/fbomb/command.rb', line 185 def matches(*args) args.each do |arg| @command.patterns.push(arg) end end |
#setup(&block) ⇒ Object
195 196 197 |
# File 'lib/fbomb/command.rb', line 195 def setup(&block) @command.setup = block end |