lib/hss/helpers/shortcut.rb in hss-1.0.1 vs lib/hss/helpers/shortcut.rb in hss-1.1.0
- old
+ new
@@ -3,11 +3,21 @@
# Allow shortcut expansion from the config
class Parser
private
def shortcut(input)
- @config['shortcuts'][input] || fail
- rescue
- raise NameError, "Shortcut does not exist #{input}"
+ @config.dig('shortcuts', input) || raise(NameError, "Shortcut does not exist #{input}")
+ end
+ end
+end
+
+unless {}.respond_to? :dig
+ ##
+ # Define dig method if it didn't exist (because Ruby predates 2.3)
+ class Hash
+ def dig(arg, *args)
+ val = self[arg]
+ return val if val.nil? || args.empty?
+ val.dig(*args)
end
end
end