Top Level Namespace
Defined Under Namespace
Modules: Enumerable, Nuggets, URI, Util Classes: Array, File, Hash, IO, Integer, Numeric, Object, Proc, Range, String, Tempfile
Constant Summary collapse
- ContentType =
Just a short-cut to make the code read nicer…
Util::ContentType
Instance Method Summary collapse
-
#foo(bar) ⇒ Object
:nodoc:.
-
#Nuggets(*nuggets) ⇒ Object
Load selected
nuggets.
Instance Method Details
#foo(bar) ⇒ Object
:nodoc:
47 48 49 50 |
# File 'lib/nuggets/string/evaluate.rb', line 47 def foo() # :nodoc: a = 'ub' .evaluate(binding) end |
#Nuggets(*nuggets) ⇒ Object
Load selected nuggets.
Examples:
# All String nuggets
Nuggets(:string)
Nuggets(String)
# Only 'msub' and 'word_wrap' String nuggets
Nuggets(:string => %w[msub word_wrap])
# Selected String nuggets and all Numeric nuggets
Nuggets(:numeric, :string => %w[msub word_wrap])
# ...you see the pattern ;-)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nuggets.rb', line 41 def Nuggets(*nuggets) loaded_nuggets = [] load_nuggets = lambda { |base, *nuggets| nuggets_by_hierarchy = nuggets.last.is_a?(Hash) ? nuggets.pop : {} nuggets.each { |nugget| begin require path = File.join(base.to_s, nugget.to_s.downcase) loaded_nuggets << path rescue LoadError # if it's a directory, load anything in it $LOAD_PATH.each { |dir| if File.directory?(dir_path = File.join(dir, path)) load_nuggets[path, *Dir[File.join(dir_path, '*')].map { |file| File.basename(file, '.rb') unless file =~ /_mixin\.rb\z/ }.compact] break end } and raise # otherwise, re-raise end } nuggets_by_hierarchy.each { |hierarchy, nuggets| nuggets = [nuggets] if nuggets.is_a?(Hash) load_nuggets[File.join(base.to_s, hierarchy.to_s.downcase), *nuggets] } } load_nuggets['nuggets', *nuggets] loaded_nuggets end |