3 ms·
Ruby, being a Perl-inspired language, has `.to_json` built in. You can do ```rb # hashes { foo: 'bar' }.to_json # numbers 28.to_json # any
by culi 3y ago
Ruby, being a Perl-inspired language, has `.to_json` built in. You can do
```rb
# hashes
{ foo: 'bar' }.to_json
# numbers
28.to_json
# anything really
['hello', 42, { lorem: "ipsum" }].to_json
```
- viralpraxis 3y agoThat’s simply not true. This method is monkeypatched by json gem
- quesera 3y agoJSON was added to Ruby stdlib in ruby-2.0.0 (2013), and has been a default gem since ruby-2.3.0 (2015). This is pretty close to "built in", I think.
- michaelcampbell 3y agoYou're both right, I think.