Skip to content

Commit

Permalink
Move Example so RDoc picks it up.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
drbrain committed Aug 4, 2006
1 parent 47cc055 commit e2c017a
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions lib/ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,9 @@
# You can redistribute and/or modify it under the same terms as Ruby.
#
# $Id$
#--
#
# TODO:
# - scope_id support
#++
#
#== Example
#
# require 'ipaddr'
#
# ipaddr1 = IPAddr.new "3ffe:505:2::1"
#
# p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
#
# p ipaddr1.to_s #=> "3ffe:505:2::1"
#
# ipaddr2 = ipaddr1.mask(48) #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>
#
# p ipaddr2.to_s #=> "3ffe:505:2::"
#
# ipaddr3 = IPAddr.new "192.168.2.0/24"
#
# p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>

require 'socket'

unless Socket.const_defined? "AF_INET6"
Expand Down Expand Up @@ -75,8 +55,27 @@ def getaddress(s)
end
end

# IPAddr provides a set of methods to manipulate an IP address. Both
# IPv4 and IPv6 are supported.
# IPAddr provides a set of methods to manipulate an IP address. Both IPv4 and
# IPv6 are supported.
#
# == Example
#
# require 'ipaddr'
#
# ipaddr1 = IPAddr.new "3ffe:505:2::1"
#
# p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
#
# p ipaddr1.to_s #=> "3ffe:505:2::1"
#
# ipaddr2 = ipaddr1.mask(48) #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>
#
# p ipaddr2.to_s #=> "3ffe:505:2::"
#
# ipaddr3 = IPAddr.new "192.168.2.0/24"
#
# p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>

class IPAddr

IN4MASK = 0xffffffff
Expand Down

0 comments on commit e2c017a

Please sign in to comment.