Skip to content

Commit dd32bfd

Browse files
committed
Add alias_switch and alias_accessor helpers.
1 parent cf7f4ac commit dd32bfd

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

README.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ For example, here is a simple "Hello, World!" commandline tool.
8080
end
8181

8282
To make the command available on the command line, add an executable
83-
to your project passing ARGV to the #execute or #run methods.
83+
to your project calling the #execute or #run methods.
8484

8585
#!usr/bin/env ruby
8686
require 'hello.rb'

lib/executable/domain.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ def #{name}?
2626
}
2727
end
2828

29+
#
30+
#
31+
#
32+
def alias_switch(name, origin)
33+
alias_method "#{name}=", "#{origin}="
34+
alias_method "#{name}?", "#{origin}?"
35+
end
36+
37+
#
38+
#
39+
#
40+
def alias_accessor(name, origin)
41+
alias_method "#{name}=", "#{origin}="
42+
alias_method "#{name}", "#{origin}"
43+
end
44+
2945
#
3046
# Inspection method. This must be redefined b/c #to_s is overridden.
3147
#
@@ -93,7 +109,9 @@ def subcommands
93109
consts.inject({}) do |h, c|
94110
c = const_get(c)
95111
if Class === c && Executable > c
96-
n = c.name.split('::').last.downcase
112+
n = c.name.split('::').last
113+
n = n.chomp('Command').chomp('CLI')
114+
n = n.downcase
97115
h[n] = c
98116
end
99117
h

0 commit comments

Comments
 (0)