lib/yaks/util.rb in yaks-0.9.0 vs lib/yaks/util.rb in yaks-0.10.0
- old
+ new
@@ -5,34 +5,34 @@
def_delegators Inflection, :singular, :singularize, :pluralize
def underscore(str)
str.gsub(/::/, '/')
- .gsub(/(?<!^|\/)([A-Z])(?=[a-z$])|(?<=[a-z])([A-Z])/, '_\1\2')
+ .gsub(%r{(?<!^|/)([A-Z])(?=[a-z$])|(?<=[a-z])([A-Z])}, '_\1\2')
.tr("-", "_")
.downcase
end
def camelize(str)
- str.gsub(/\/(.?)/) { "::#{ $1.upcase }" }
+ str.gsub(%r{/(.?)}) { "::#{ $1.upcase }" }
.gsub!(/(?:^|_)(.)/) { $1.upcase }
end
def slice_hash(hash, *keys)
- keys.each_with_object({}) {|k,dest| dest[k] = hash[k] if hash.key?(k) }
+ keys.each_with_object({}) {|k, dest| dest[k] = hash[k] if hash.key?(k) }
end
def reject_keys(hash, *keys)
- hash.keys.each_with_object({}) {|k,dest| dest[k] = hash[k] unless keys.include?(k) }
+ hash.keys.each_with_object({}) {|k, dest| dest[k] = hash[k] unless keys.include?(k) }
end
def symbolize_keys(hash)
- hash.each_with_object({}) {|(k,v), hsh| hsh[k.to_sym] = v}
+ hash.each_with_object({}) {|(k, v), hsh| hsh[k.to_sym] = v}
end
def extract_options(args)
- args.last.is_a?(Hash) ? [args[0..-2], args.last] : [args, {}]
+ args.last.instance_of?(Hash) ? [args[0..-2], args.last] : [args, {}]
end
# Turn what is maybe a Proc into its result (or itself)
#
# When input can be either a value or a proc that returns a value,
@@ -44,11 +44,11 @@
#
# @param [Object|Proc] maybe_proc
# A proc or a plain value
# @param [Object] context
# (optional) A context used to instance_eval the proc
- def Resolve(maybe_proc, context = nil)
+ def Resolve(maybe_proc, context = nil) # rubocop:disable Style/MethodName
if maybe_proc.respond_to?(:to_proc) && !maybe_proc.instance_of?(Symbol)
if context
if maybe_proc.arity > 0
context.instance_eval(&maybe_proc)
else
@@ -69,8 +69,7 @@
$stderr.puts "WARNING: #{self.class}##{name} is deprecated, use `#{actual}'. at #{caller.first}"
public_send(actual, *args, &block)
end
end
end
-
end
end