- How do you compare types? i.e.
w = nil
x = “foo” if w != nil # still assigns foo to x
I don’t quite undersatnd your question. Could you elaborate?
- What is the official irc network and channel for ruby? (#ruby-lang on
what network?)
It’s irc.freenode.net. It should really be posted somewhere.
- I need to take an ip and convert it to base10. Are there base
conversion methods in Ruby? (I’ve found some addons and exstensions, but I
need something that’s already built in if possible)
I don’t think so. Why don’t you just write your own?
What’s the format of your input?
···
On Tue, Mar 04, 2003 at 03:35:32AM +0900, ghost-no-spam@cotse.net wrote:
–
Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137
Hmm, that doesn’t do any decimal conversion, just byte ordering. Are you
thinking of the C functions inet_aton and inet_ntoa which convert between
strings and struct in_addr?
In Ruby, the socket functions take the string representation directly, so
it’s not normally necessary to convert: e.g.
require ‘socket’
t = TCPSocket.new(‘127.0.0.1’, 23) # connect to my telnet port
If you really want it as a 4-byte integer then you can convert easily, but
beware that IP addrs are likely to be represented as Bignum rather than
Fixnum because the size of Fixnum is 31 bits:
class Socket
def Socket.aton(a)
res = 0
a.split(/./).each { |byte| res<<=8; res|=byte.to_i }
res
end
end
ip = ‘206.27.238.1’
puts Socket.aton(ip) #>> 3457936897
printf “%08X\n”, Socket.aton(ip) #>> CE1BEE01
Is that what you were looking for?
Regards,
Brian.
···
On Tue, Mar 04, 2003 at 06:16:03AM +0900, ghost-no-spam@cotse.net wrote:
I don’t think so. Why don’t you just write your own?
I may have to have to, but regrettably, math is not my strongest point.
What’s the format of your input?
Standard IP addy, “127.0.0.1”. I know what I am looking for can be
accompished with the hton() function in C, (converts host to network byte
order).