Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `as_json' for Hash #30

Closed
parkr opened this issue Jun 16, 2014 · 6 comments
Closed

undefined method `as_json' for Hash #30

parkr opened this issue Jun 16, 2014 · 6 comments

Comments

@parkr
Copy link

parkr commented Jun 16, 2014

Irked by this when using GeoRuby standalone to modify GeoJSON files.

/Users/parker/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/georuby-2.2.1/lib/geo_ruby/geojson.rb:40:in `as_json': undefined method `as_json' for #<Hash:0x007fb57a945958> (NoMethodError)
    from /Users/parker/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/georuby-2.2.1/lib/geo_ruby/geojson.rb:44:in `to_json'
    from /Users/parker/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/georuby-2.2.1/lib/geo_ruby/geojson.rb:70:in `to_json'
    from /Users/parker/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/georuby-2.2.1/lib/geo_ruby/geojson.rb:70:in `to_json'

Do I need ActiveSupport? ActiveModel? If so, how can I avoid it?

@darkside
Copy link

From the top of my head I'd say ActiveSupport core extensions. You can roll your own as_json for Hash, obviously.

@parkr
Copy link
Author

parkr commented Jun 16, 2014

It's just:

class Hash
  def as_json(opts = {})
    self
  end
end

ya? Seems like a a good idea to add that to this project in case we're not working with Active*.

@darkside
Copy link

Yup, we could have something like that as a default Hash extension if ActiveSupport (or the method) is not present.

@nofxx
Copy link
Owner

nofxx commented Sep 20, 2014

I've pushed some clean ups and changes. Please provide a use case @parkr , just need a spec to understand this part of the code ;)

@parkr
Copy link
Author

parkr commented Sep 21, 2014

@nofxx I was writing out GeoJSON, like so: https://github.com/parkr/would-patronize-again/blob/master/lib/patronize.rb

I got the above error when trying to turn the geographic information into GeoJSON and writing it out to a file.

@nofxx
Copy link
Owner

nofxx commented Dec 6, 2014

Hello @parkr, should be working fine now. (v2.5.1)
No need for ActiveWhatever, #to_json is from 'json' gem:

*>   {a: 1}.to_json
=> "{"a":1}"
>> JSON
=> JSON
>> ActiveSupport
NameError: uninitialized constant ActiveSupport
    from (irb):4
    from /usr/bin/irb:11:in `<main>'

@nofxx nofxx closed this as completed Dec 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants