# HTTP:Post and Ruby 1.8.2

**URL:** <https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146>\
**Category:** Ruby\
**Created:** [April 29, 2006, 2:01am UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146 "2006-04-29T02:01:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [April 29, 2006, 2:01am UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/1 "2006-04-29T02:01:10Z")

</div>

It seems HTTP:Post was changed a bit in 1.8.3+

I have publicly available code and I’d like it to support either Ruby  
version.

Should I actually check the Ruby version? How would I actually do that?  
None of my searches paid off.

Alternatively, I could catch the ‘NoMethod’ exception, but that would  
mean  
it could potentially take the 1.8.2 code path if I actually goofed a bit  
in  
my 1.8.4 path.

\_jason

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [April 29, 2006, 2:10am UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/2 "2006-04-29T02:10:23Z")

</div>

On Apr 28, 2006, at 7:58 PM, Jason P. wrote:

> Should I actually check the Ruby version? How would I actually do  
> that?  
> None of my searches paid off.

Should you? That’s debatable. Could you? Absolutely.

% ruby -e ‘p VERSION’  
“1.8.4”

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [April 29, 2006, 2:25am UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/3 "2006-04-29T02:25:26Z")

</div>

On 4/28/06, Logan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> % ruby -e ‘p VERSION’  
> “1.8.4”

while I guess I _could_ call eval and get that, is there a way to check  
the  
ruby version at runtime? A global var or something?

I’ve decided to just change my code to something that works in both  
versions, but I’m still curious how to do this 🙂

\_jason

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [April 29, 2006, 2:40am UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/4 "2006-04-29T02:40:40Z")

</div>

Jason P. wrote:

> On 4/28/06, Logan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Should you? That’s debatable. Could you? Absolutely.
> > 
> > % ruby -e ‘p VERSION’  
> > “1.8.4”
> 
> while I guess I _could_ call eval and get that, is there a way to check the  
> ruby version at runtime? A global var or something?

Yes. See the example above.

🙂

–  
James B.

[http://www.ruby-doc.org](http://www.ruby-doc.org) - Ruby Help & Documentation  
[Ruby Code & Style](http://www.artima.com/rubycs/) - The Journal By & For Rubyists  
[http://www.rubystuff.com](http://www.rubystuff.com) - The Ruby Store for Ruby Stuff  
[http://refreshingcities.org](http://refreshingcities.org) - Design, technology, usability

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [April 29, 2006, 2:43am UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/5 "2006-04-29T02:43:40Z")

</div>

On Apr 28, 2006, at 8:22 PM, Jason P. wrote:

> > 
> 
> \_jason

Perhaps my example wasn’t clear:

#!/usr/bin/env ruby  
if VERSION \>= “1.8.4”  
# use new HTTP#post  
elsif VERSION == “1.8.3”  
# use 1.8.3 #post  
else  
# use 1.8.2 #post  
end

**END**

You don’t need to call eval, VERSION is a global constant.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [April 29, 2006, 2:40am UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/6 "2006-04-29T02:40:33Z")

</div>

On 4/28/06, Jason P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 4/28/06, Logan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > % ruby -e ‘p VERSION’  
> > “1.8.4”
> 
> while I guess I _could_ call eval and get that, is there a way to check the  
> ruby version at runtime? A global var or something?

VERSION

🙂

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [April 29, 2006, 2:46am UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/7 "2006-04-29T02:46:41Z")

</div>

> > while I guess I _could_ call eval and get that, is there a way to check  
> > the  
> > ruby version at runtime? A global var or something?
> 
> VERSION
> 
> 🙂

no! no! no! no! no! no! no! no! no! no! no! no!

_runs screaming down the hall pulling out his hair_

of course it is… after glancing at the previous reply, I thought Logan  
was  
just doing a % ruby -v

such an idiot I am.

🙂

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [April 29, 2006, 9:06am UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/8 "2006-04-29T09:06:45Z")

</div>

On Sat, Apr 29, 2006 at 09:07:31AM +0900, Logan C. wrote:

> On Apr 28, 2006, at 7:58 PM, Jason P. wrote:
> 
> > Should I actually check the Ruby version? How would I actually do that?  
> > None of my searches paid off.
> 
> Should you? That’s debatable. Could you? Absolutely.
> 
> % ruby -e ‘p VERSION’  
> “1.8.4”

Use RUBY\_VERSION to make that future-proof:

$ ruby19 -ve “p VERSION”  
ruby 1.9.0 (2006-02-24) [i686-linux]  
-e:1: uninitialized constant VERSION (NameError)  
$ ruby19 -ve “p RUBY\_VERSION”  
ruby 1.9.0 (2006-02-24) [i686-linux]  
“1.9.0”  
$ ruby -ve “p RUBY\_VERSION”  
ruby 1.8.4 (2005-12-24) [i686-linux]  
“1.8.4”

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [May 3, 2006, 7:08pm UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/9 "2006-05-03T19:08:29Z")

</div>

Jason P. wrote:

> Should I actually check the Ruby version? How would I actually do that?  
> None of my searches paid off.
> 
> Alternatively, I could catch the ‘NoMethod’ exception, but that would mean  
> it could potentially take the 1.8.2 code path if I actually goofed a bit in  
> my 1.8.4 path.

Instead of using the RUBY\_VERSION constant, it’s probably better to use  
object.respond\_to?(:method\_name) to determine which version you are  
dealing with.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [May 3, 2006, 7:09pm UTC](https://www.ruby-forum.com/t/http-post-and-ruby-1-8-2/59146/10 "2006-05-03T19:09:35Z")

</div>

> Instead of using the RUBY\_VERSION constant, it’s probably better to use  
> object.respond\_to?(:method\_name) to determine which version you are  
> dealing with.
> 
> –  
> John L.  
> [http://wiseheartdesign.com/](http://wiseheartdesign.com/)
> 
> I was considering that, but it seemed like it would be more consistent to  
> just verify that it runs on each version. Also, it lets me have a nice  
> clean chunk at the top of the code with a RUBY\_VERSION check that  
> extends  
> the classes if necessary.
