<commit_before>require 'representable'
require 'representable/bindings/json_bindings'
require 'json'

module Representable
  # Brings #to_xml, #to_hash, #from_xml and #from_hash to your object.
  #
  # Note: The authorative methods are #to_hash and #from_hash, if you override #to_json instead,
  # things might work as expected.
  module JSON
    BINDING_FOR_TYPE = {  # TODO: refactor #representable_accessor for better extendability.
      :text     => TextBinding,
    }
    
    def self.included(base)
      base.class_eval do
        include Representable
        extend ClassMethods
      end
    end
    
    
    module ClassMethods
      def binding_for_definition(definition)
        (BINDING_FOR_TYPE[definition.sought_type] or ObjectBinding).new(definition)
      end
    
      # Creates a new object from the passed JSON document.
      def from_json(*args, &block)
        new.from_json(*args, &block)
      end
      
      def from_hash(*args, &block)
        new.from_hash(*args, &block)
      end
    end
    
    # Parses the body as JSON and delegates to #from_hash.
    def from_json(data, *args, &block)
      data = ::JSON[data]
      from_hash(data, *args, &block)
    end
    
    def from_hash(data, options={}, &block)
      if wrap = options[:wrap] || self.class.representation_wrap
        data = data[wrap.to_s]
      end
      
      update_properties_from(data, &block)
    end
    
    def to_hash(options={})
      hash = create_representation_with({})
      
      return hash unless wrap = options[:wrap] || self.class.representation_wrap
      
      {wrap => hash}
    end
    
    # Returns a JSON string representing this object.
    def to_json(options={})
      to_hash(options).to_json
    end
  end
end<commit_msg>to_json now passes args correctly.<commit_after>require 'representable'
require 'representable/bindings/json_bindings'
require 'json'

module Representable
  # Brings #to_xml, #to_hash, #from_xml and #from_hash to your object.
  #
  # Note: The authorative methods are #to_hash and #from_hash, if you override #to_json instead,
  # things might work as expected.
  module JSON
    BINDING_FOR_TYPE = {  # TODO: refactor #representable_accessor for better extendability.
      :text     => TextBinding,
    }
    
    def self.included(base)
      base.class_eval do
        include Representable
        extend ClassMethods
      end
    end
    
    
    module ClassMethods
      def binding_for_definition(definition)
        (BINDING_FOR_TYPE[definition.sought_type] or ObjectBinding).new(definition)
      end
    
      # Creates a new object from the passed JSON document.
      def from_json(*args, &block)
        new.from_json(*args, &block)
      end
      
      def from_hash(*args, &block)
        new.from_hash(*args, &block)
      end
    end
    
    # Parses the body as JSON and delegates to #from_hash.
    def from_json(data, *args, &block)
      data = ::JSON[data]
      from_hash(data, *args, &block)
    end
    
    def from_hash(data, options={}, &block)
      if wrap = options[:wrap] || self.class.representation_wrap
        data = data[wrap.to_s]
      end
      
      update_properties_from(data, &block)
    end
    
    def to_hash(options={}, &block)
      hash = create_representation_with({}, &block)
      
      return hash unless wrap = options[:wrap] || self.class.representation_wrap
      
      {wrap => hash}
    end
    
    # Returns a JSON string representing this object.
    def to_json(*args, &block)
      to_hash(*args, &block).to_json
    end
  end
end
{'fraction_non_alphanumeric': 0.08856502242152467, 'fraction_numerical': 0.0, 'mean_word_length': 2.56187624750499, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5597945', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1087, 'n_words': 297}