Sha256: 3e903597ffff2b6b0e731ceefbf094516908ff0f3ae813f4a7e8733478f2e734
Contents?: true
Size: 925 Bytes
Versions: 2
Compression:
Stored size: 925 Bytes
Contents
# angular_init (short-name: ngi) # Copyright 2015 Joshua Beam # github.com/joshbeam/angular_init # MIT License # Since ngi is an AngularJS tool and the users # are familiar with JavaScript, this module of classes # prints a string version of a Ruby hash or array # as it would appear in normal JavaScript syntax # For example: # { "hello" => "world" } # becomes: # { 'hello': 'world' } # and ["some","array"] # becomes: # ['some','array'] module JSer def to_str to_s.gsub(/\"/, "'").gsub(/\=\>/, ': ') end # A JSer class # Usage: # JSHash.new({"hello" => "world"}).to_str class JSHash < Hash def initialize(hash) super hash.each do |key, val| self[key] = val end end include JSer end # Another JSer class # Usage: # JSArray.new(["some","array"]).to_str class JSArray < Array def initialize(array) super end include JSer end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ngi-0.2.3 | lib/ngi/utils/jser.rb |
ngi-0.2.2 | lib/ngi/utils/jser.rb |