Sha256: 9253d2204de8e36c3028fc45ca630a2b0e7475f98124629c32a4f7184fafab37
Contents?: true
Size: 1.21 KB
Versions: 10
Compression:
Stored size: 1.21 KB
Contents
module Vedeu # A module for common methods used throughout Vedeu. # module Common # Removes the module part from the expression in the string. # # @example # demodulize('Vedeu::DSL::Interface') # => "Interface" # # @param klass [Class|String] # @return [void] def demodulize(klass) klass = klass.to_s klass[(klass.rindex('::') + 2)..-1] end # Converts a class name to a lowercase snake case string. # # @example # snake_case(MyClassName) # => "my_class_name" # snake_case(NameSpaced::ClassName) # => "name_spaced/class_name" # # @param name [String] # @return [String] def snake_case(name) name.gsub!(/::/, '/') name.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') name.gsub!(/([a-z\d])([A-Z])/, '\1_\2') name.tr!('-', '_') name.downcase! name end # Returns a boolean indicating whether a variable has a useful value. # # @param variable [String|Symbol|Array|Fixnum] The variable to check. # @return [Boolean] def present?(variable) return true if variable.is_a?(Fixnum) return true unless variable.nil? || variable.empty? false end end # Common end # Vedeu
Version data entries
10 entries across 10 versions & 1 rubygems