Sha256: 8ee57ff2f9fc3c05f0a6120e89803e88da69f023f60d084d273323e25dee1367

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

# content_or_self
[Hash, OpenObject].each do |aclass|
  aclass.class_eval do 
    def hash?; true end
  end
end

NilClass.class_eval do
  def content; "" end
  def hash?; false end
end

String.class_eval do
  def content; self end
  def hash?; false end
end

# OpenObject
OpenObject.class_eval do
  HTML_ATTRIBUTES = [:id, :class]
  
  def merge_html_attributes hash
    # html attributes
    result = {}
    HTML_ATTRIBUTES.each{|k| result[k.to_s] = self[k] if include? k}
    html_attributes.each{|k, v| result[k.to_s] = v} if html_attributes?
    
    # merging html attributes with hash
    hash.each do |k, v|
      k = k.to_s
      if result.include?(k) and v.is_a?(String)
        string = result[k].should! :be_a, [Symbol, String]
        result[k] = "#{result[k]}#{v}"
      else
        result[k] = v
      end
    end
    result
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crystal-ext-0.0.3 lib/abstract_interface/support.rb
crystal-ext-0.0.2 lib/abstract_interface/support.rb