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.
Jason P. (Guest)
on 2006-04-29 04: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
Logan C. (Guest)
on 2006-04-29 04:10
(Received via mailing list)
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"
Jason P. (Guest)
on 2006-04-29 04:25
(Received via mailing list)
On 4/28/06, Logan C. <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
Gregory B. (Guest)
on 2006-04-29 04:40
(Received via mailing list)
On 4/28/06, Jason P. <removed_email_address@domain.invalid> wrote:
> On 4/28/06, Logan C. <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

:)
James B. (Guest)
on 2006-04-29 04:40
(Received via mailing list)
Jason P. wrote:
> On 4/28/06, Logan C. <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       - 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
Logan C. (Guest)
on 2006-04-29 04:43
(Received via mailing list)
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.
Jason P. (Guest)
on 2006-04-29 04: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.

:)
Mauricio F. (Guest)
on 2006-04-29 11:06
(Received via mailing list)
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"
John W. Long (Guest)
on 2006-05-03 21:08
(Received via mailing list)
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.
Jason P. (Guest)
on 2006-05-03 21: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 L.
> 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.