Forum: Ruby HTTP:Post and Ruby 1.8.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0360fb06cceca9d2de741627edc8c36c?d=identicon&s=25 Jason Persampieri (Guest)
on 2006-04-29 02:01
(Received via mailing list)
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
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-04-29 02:10
(Received via mailing list)
On Apr 28, 2006, at 7:58 PM, Jason Persampieri 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"
0360fb06cceca9d2de741627edc8c36c?d=identicon&s=25 Jason Persampieri (Guest)
on 2006-04-29 02:25
(Received via mailing list)
On 4/28/06, Logan Capaldo <logancapaldo@gmail.com> 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
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2006-04-29 02:40
(Received via mailing list)
On 4/28/06, Jason Persampieri <jason@persampieri.net> wrote:
> On 4/28/06, Logan Capaldo <logancapaldo@gmail.com> 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

:)
Bc6d88907ce09158581fbb9b469a35a3?d=identicon&s=25 James Britt (Guest)
on 2006-04-29 02:40
(Received via mailing list)
Jason Persampieri wrote:
> On 4/28/06, Logan Capaldo <logancapaldo@gmail.com> 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 Britt

http://www.ruby-doc.org       - Ruby Help & Documentation
http://www.artima.com/rubycs/ - The Journal By & For Rubyists
http://www.rubystuff.com      - The Ruby Store for Ruby Stuff
http://refreshingcities.org   - Design, technology, usability
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-04-29 02:43
(Received via mailing list)
On Apr 28, 2006, at 8:22 PM, Jason Persampieri 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.
0360fb06cceca9d2de741627edc8c36c?d=identicon&s=25 Jason Persampieri (Guest)
on 2006-04-29 02:46
(Received via mailing list)
>
> > 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.

:)
Dd76a12d66f843de5c5f8782668e7127?d=identicon&s=25 Mauricio Fernandez (Guest)
on 2006-04-29 09:06
(Received via mailing list)
On Sat, Apr 29, 2006 at 09:07:31AM +0900, Logan Capaldo wrote:
> On Apr 28, 2006, at 7:58 PM, Jason Persampieri 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"
6ec6f77ea603dd75b3a7a7775b059e79?d=identicon&s=25 John W. Long (Guest)
on 2006-05-03 19:08
(Received via mailing list)
Jason Persampieri 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.
0360fb06cceca9d2de741627edc8c36c?d=identicon&s=25 Jason Persampieri (Guest)
on 2006-05-03 19:09
(Received via mailing list)
>
> 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 Long
> 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.
This topic is locked and can not be replied to.