Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Remove superfluous (and erroneous) module includes from IPAddress::IPv6 #15

Closed
wants to merge 1 commit into from

2 participants

@pvdb

Don't include modules for which the mandatory primitives aren't implemented.

IPAddress::IPv6 doesn't implement the each method (required for the Enumerable module) nor the <=> operator (required for the Comparable module), so it doesn't make sense to include these modules.

Including these modules makes the IPv6 instances respond to methods like to_a (from the Enumerable module) and between? (from the Comparable module), but these methods result in a NoMethodError exception (for the each and <=> methods respectively).

Example:

irb > IPAddress('::1').to_a
NoMethodError: undefined method `each' for #<IPAddress::IPv6:0x1016b3990>
    from (irb):1:in `to_a'
    from (irb):1

irb > IPAddress('::1').between? 1, 2
NoMethodError: undefined method `<=>' for #<IPAddress::IPv6:0x1016c5cd0>
    from (irb):1:in `between?'
    from (irb):1

From the standard Ruby rdoc:

ri Enumerable

The class must provide a method `each`, which yields successive members of the collection. 

and:

ri Comparable

The class must define the `<=>` operator, which compares the receiver against another object
@pvdb pvdb Don't include modules for which the mandatory primitives aren't imple…
…mented.

IPAddress::IPv6 doesn't implement the *each* method (required for the *Enumerable* module) nor the *<=>* operator (required for the *Comparable* module), so it doesn't make sense to include these modules.

Including these modules makes the IPv6 instances respond to methods like *to_a* (from the *Enumerable* module) and *between?* (from the *Comparable* module), but these methods result in a NoMethodError exception (for the *each* and *<=>* methods respectively).

Example:

irb > IPAddress('::1').to_a
NoMethodError: undefined method `each' for #<IPAddress::IPv6:0x1016b3990>
	from (irb):1:in `to_a'
	from (irb):1

irb > IPAddress('::1').between? 1, 2
NoMethodError: undefined method `<=>' for #<IPAddress::IPv6:0x1016c5cd0>
	from (irb):1:in `between?'
	from (irb):1


From the standard Ruby rdoc:

ri Enumerable

The class must provide a method *each*, which yields successive members of the collection. 

ri Comparable

The class must define the *<=>* operator, which compares the receiver against another object
7361d75
@bluemonk
Owner

Related to #13
I will include IPv6#<=> and IPv6#each in the next release.

Thanks for your pull request.

@pvdb

Cheers for the reply, bluemonk... looking forward to the next release of this awesome gem (I've learned quite a lot about IP addresses in using it, lots of things I didn't even know I didn't know :-)

I'll close the pull request in anticipation of the next gem release.

@pvdb pvdb closed this
@bluemonk
Owner

Thanks very much, you're too nice :-)
I've learned a lot myself while developing the library, it's incredible how an apparently simple topic like IP addresses could be so complex sometimes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 2, 2011
  1. @pvdb

    Don't include modules for which the mandatory primitives aren't imple…

    pvdb authored
    …mented.
    
    IPAddress::IPv6 doesn't implement the *each* method (required for the *Enumerable* module) nor the *<=>* operator (required for the *Comparable* module), so it doesn't make sense to include these modules.
    
    Including these modules makes the IPv6 instances respond to methods like *to_a* (from the *Enumerable* module) and *between?* (from the *Comparable* module), but these methods result in a NoMethodError exception (for the *each* and *<=>* methods respectively).
    
    Example:
    
    irb > IPAddress('::1').to_a
    NoMethodError: undefined method `each' for #<IPAddress::IPv6:0x1016b3990>
    	from (irb):1:in `to_a'
    	from (irb):1
    
    irb > IPAddress('::1').between? 1, 2
    NoMethodError: undefined method `<=>' for #<IPAddress::IPv6:0x1016c5cd0>
    	from (irb):1:in `between?'
    	from (irb):1
    
    
    From the standard Ruby rdoc:
    
    ri Enumerable
    
    The class must provide a method *each*, which yields successive members of the collection. 
    
    ri Comparable
    
    The class must define the *<=>* operator, which compares the receiver against another object
This page is out of date. Refresh to see the latest.
Showing with 0 additions and 3 deletions.
  1. +0 −3  lib/ipaddress/ipv6.rb
View
3  lib/ipaddress/ipv6.rb
@@ -61,9 +61,6 @@ module IPAddress;
class IPv6
include IPAddress
- include Enumerable
- include Comparable
-
#
# Format string to pretty print IPv6 addresses
Something went wrong with that request. Please try again.