Class: DiamondLang::Helpers::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/diamond-lang/helpers/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *args, &block) ⇒ Command

Returns a new instance of Command.



13
14
15
16
17
18
19
20
21
# File 'lib/diamond-lang/helpers/command.rb', line 13

def initialize(name, *args, &block)
  @command = name.freeze
  @arguments = args.flatten
  if block
    chain = CommandChain.new self
    block.call(chain)
    @chain = chain.commands.freeze
  end
end

Instance Attribute Details

#chainObject (readonly)

Returns the value of attribute chain.



12
13
14
# File 'lib/diamond-lang/helpers/command.rb', line 12

def chain
  @chain
end

#commandObject

Returns the value of attribute command.



11
12
13
# File 'lib/diamond-lang/helpers/command.rb', line 11

def command
  @command
end

Instance Method Details

#inspectObject



25
26
27
# File 'lib/diamond-lang/helpers/command.rb', line 25

def inspect
  [@command, *@arguments].join(" ") + ", success: " + @chain.inspect
end

#to_block(type = :chain) ⇒ Object



31
32
33
# File 'lib/diamond-lang/helpers/command.rb', line 31

def to_block(type=:chain)
  CommandBlock.new self, type, 0
end

#to_minecartObject



28
29
30
# File 'lib/diamond-lang/helpers/command.rb', line 28

def to_minecart
  CommandBlockMinecart.new self
end

#to_sObject



22
23
24
# File 'lib/diamond-lang/helpers/command.rb', line 22

def to_s
  [@command, *@arguments].join " "
end