Sha256: 8412857b352aa1eb616622326d4eb2f0b8d634169010de4041508dec5fef6dec

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

class Object
  def to_interlock_tag
    string = to_s
    string = "empty_string" if string.empty? 
    string.escape_tag_fragment
  end
end

class NilClass
  def to_interlock_tag
    "untagged".escape_tag_fragment
  end
end

class Hash
  alias :fetch_safely :[]

  def value_for_indifferent_key(key)
    fetch_safely(key) or fetch_safely(key.to_s) or fetch_safely(key.to_sym)
  end
  
  alias :v :value_for_indifferent_key
  
  def indifferentiate!
    class << self
      def [](key); value_for_indifferent_key(key); end
    end        
    self
  end

  def indifferentiate
    self.dup.indifferentiate!    
  end
  
  def deep_symbolize_keys!
    symbolize_keys!
    values.each do |value|
      value.deep_symbolize_keys! if value.is_a? Hash
    end
  end
  
end

class Array  
  unless Array.instance_methods.include? "extract_options!"
  
    def extract_options!
      # Method added in Rails rev 7217
      last.is_a?(Hash) ? pop : {}
    end
    
  end  
end

class String
  def field(i)
    split(":")[i]
  end
  
  def escape_tag_fragment
    gsub(':', '-').gsub(/[^\w\d\-;]/, '_')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
interlock-1.0 lib/interlock/core_extensions.rb
interlock-1.1 lib/interlock/core_extensions.rb