bad design in gem rest-client
updated 2011-11-29 22:56 pull request sent
This works though:
What if the code is running on a Ruby implementation which
does not support COW (copy-on-write) for strings?
And this didn't work either:
require 'webmock' require 'rest-client' WebMock::API.stub_request(:get, 'http://host/').to_return(:body => '123') RestClient.get('http://host/') # "123" RestClient.get('http://host/').to_s # "123" RestClient.get('http://host/').to_str # "123" RestClient.get('http://host/').class # Stringok, here comes the (not) fun part:
RestClient.get('http://host/').to_i # 200 RestClient.get('http://host/').to_s.to_i # 200 RestClient.get('http://host/').to_str.to_i # 200 String(RestClient.get('http://host/')).to_i # 200Can we remove that offending and surprising
to_i
?This works though:
RestClient.get('http://host/').dup.to_i # 123 String.new(RestClient.get('http://host/')).to_i # 123 "#{RestClient.get('http://host/')}".to_i # 123But I don't want to copy the strings all the time!
What if the code is running on a Ruby implementation which
does not support COW (copy-on-write) for strings?
And this didn't work either:
RestClient.get('http://host/').clone.to_i # 200Or maybe I should switch to Tony's http?
0 retries:
Post a Comment
Note: Only a member of this blog may post a comment.