Method: JSONBuilder::Compiler#initialize
- Defined in:
- lib/json_builder/compiler.rb
#initialize(options = {}) ⇒ Compiler
Public: Creates a new Compiler instance used to hold any and all JSONBuilder::Member objects.
options - Hash of options used to modify JSON output.
Examples
json = JSONBuilder::Compiler.new(:callback => false)
json.compile do
name 'Garrett'
end
json.finalize
# => {"name": "Garrett"}
Returns instance of JSONBuilder::Compiler.
46 47 48 49 50 51 52 53 54 |
# File 'lib/json_builder/compiler.rb', line 46 def initialize(={}) @_members = [] @_scope = .fetch(:scope, nil) @_callback = .fetch(:callback, true) @_pretty_print = .fetch(:pretty, false) # Only copy instance variables if there is a scope and presence of Rails copy_instance_variables_from(@_scope) if @_scope end |