lib/ordu.rb in ordu-0.0.3 vs lib/ordu.rb in ordu-0.0.4
- old
+ new
@@ -34,22 +34,20 @@
# Parse options in order, and call commands for non-option arguments (if the
# command exists). This is how programs are exected.
def parse!(args)
args = order!(args)
unless args.empty?
- if commands.key?(args.first)
- return commands[args.shift].parse!(args)
- end
+ return commands[args.shift].parse!(args) if commands.key?(args.first)
end
run(*args)
end
# A string which summarizes the commands - shown in the help
def command_summary
return if commands.empty?
w = commands.keys.map(&:length).max
- lines = ["Available commands:"]
+ lines = ['Available commands:']
lines += commands.map { |k, v| " %-#{w}s %s" % [k, v.desc] }
lines.join("\n")
end
# Parses a new instance. Note that this must be the top-level, since you
@@ -68,15 +66,17 @@
def name
@name ||= self.class.name
end
def self.name(name = nil)
- name ? @name = name : @name
+ @name = name if name
+ @name if instance_variable_defined?(:@name)
end
def self.desc(desc = nil)
- desc ? @desc = desc : @desc
+ @desc = desc if desc
+ @desc if instance_variable_defined?(:@desc)
end
# Runs the action for this Ordu instance.
def run(*args)
return instance_exec(*args, &@action) if @action
@@ -127,8 +127,8 @@
end
# Defines the action to be run once parsing is finished.
def self.action(&block)
@action = block if block_given?
- @action ||= lambda { }
+ @action ||= lambda { |*args| }
end
end