Skip to content

Commit

Permalink
Wrap const_defined? in begin/rescue
Browse files Browse the repository at this point in the history
  • Loading branch information
YellowApple committed Sep 5, 2015
1 parent 204d94d commit 5c76fdb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/bales/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,14 @@ def self.parse_command_name(argv)
.map { |p| p.capitalize }
.join
name = "#{const}::#{part}"
if const.const_defined? name
const = eval(name)
depth += 1
else
begin
if const.const_defined? name
const = eval(name)
depth += 1
else
break
end
rescue NameError
break
end
end
Expand Down
9 changes: 7 additions & 2 deletions lib/bales/command/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ def self.commands(ns)
end

ns.constants
.select { |c| ns.const_defined? "#{ns}::#{c}" }
.select { |c| eval("#{ns}::#{c}").class == Class }
.select { |c|
begin
ns.const_defined? "#{ns}::#{c}"
rescue NameError
false
end
}.select { |c| eval("#{ns}::#{c}").class == Class }
.select { |c| eval("#{ns}::#{c}") <= Bales::Command }
.map { |c| eval "#{ns}::#{c}" }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bales/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bales
VERSION="0.1.1"
VERSION="0.1.2"
end

0 comments on commit 5c76fdb

Please sign in to comment.