Sha256: 061ecb712494b5cdeeab1c9066311470716031a22aeaca415e1571847b1e4dae

Contents?: true

Size: 727 Bytes

Versions: 28

Compression:

Stored size: 727 Bytes

Contents

class Object
  def rson?
    false
  end
end

[
  FalseClass,
  TrueClass,
  Numeric,
  String,
  Symbol,
  NilClass,
].each do |klass|
  klass.class_eval do
    def to_rson options = {}
      self
    end
    
    def rson?
      true
    end
  end
end

Array.class_eval do
  def to_rson options = {}
    collect{|v| v.to_rson(options)}
  end
  
  def rson?
    all?{|v| v.rson?}
  end
end
  
[Hash, OpenObject].each do |klass|
  klass.class_eval do
    def to_rson options = {}
      r = self.class.new
      each do |k, v|
        r[k.to_rson(options)] = v.to_rson(options)
      end
      r
    end
  
    def rson?
      each do |k, v|
        return false unless k.rson? and v.rson?
      end
      true
    end
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
rad_core-0.2.6 lib/rad/_support/rson.rb
rad_core-0.2.5 lib/rad/_support/rson.rb
rad_core-0.2.4 lib/rad/_support/rson.rb
rad_core-0.2.3 lib/rad/_support/rson.rb
rad_core-0.2.2 lib/rad/_support/rson.rb
rad_core-0.2.1 lib/rad/_support/rson.rb
rad_core-0.2.0 lib/rad/_support/rson.rb
rad_core-0.0.30 lib/rad/_support/rson.rb
rad_core-0.0.29 lib/rad/_support/rson.rb
rad_core-0.0.28 lib/rad/_support/rson.rb
rad_core-0.0.27 lib/rad/_support/rson.rb
rad_core-0.0.26 lib/rad/_support/rson.rb
rad_core-0.0.25 lib/rad/_support/rson.rb
rad_core-0.0.24 lib/rad/_support/rson.rb
rad_core-0.0.23 lib/rad/_support/rson.rb
rad_core-0.0.22 lib/rad/_support/rson.rb
rad_core-0.0.21 lib/rad/_support/rson.rb
rad_core-0.0.20 lib/rad/_support/rson.rb
rad_core-0.0.19 lib/rad/_support/rson.rb
rad_core-0.0.18 lib/rad/_support/rson.rb