Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link_local? defined twice in lib/ipaddress/ipv6.rb #99

Open
bcoles opened this issue Dec 9, 2017 · 4 comments
Open

link_local? defined twice in lib/ipaddress/ipv6.rb #99

bcoles opened this issue Dec 9, 2017 · 4 comments

Comments

@bcoles
Copy link

bcoles commented Dec 9, 2017

Noticed this error during tests in an unrelated project:

/usr/local/rvm/gems/ruby-2.3.0/gems/ipaddress-0.8.3/lib/ipaddress/ipv6.rb:437: warning: method redefined; discarding old link_local?
/usr/local/rvm/gems/ruby-2.3.0/gems/ipaddress-0.8.3/lib/ipaddress/ipv6.rb:405: warning: previous definition of link_local? was here

Seems link_local? is defined twice in lib/ipaddress/ipv6.rb

https://github.com/ipaddress-gem/ipaddress/blob/master/lib/ipaddress/ipv6.rb#L405

    #
    # Returns true if the address is a link local address
    #
    def link_local?
      @groups[0] == 0xfe80
    end

https://github.com/ipaddress-gem/ipaddress/blob/master/lib/ipaddress/ipv6.rb#L437

    #
    # Checks if an IPv6 address objects belongs
    # to a link-local network RFC4291
    #
    # Example:
    #
    #   ip = IPAddress "fe80::1"
    #   ip.link_local?
    #     #=> true
    #
    def link_local?
      [self.class.new("fe80::/64")].any? {|i| i.include? self}
    end
@bcoles
Copy link
Author

bcoles commented Dec 17, 2017

The second instance of link_local? was added in #83

@watzon
Copy link

watzon commented Jul 2, 2019

I was about to add this, good catch

@javierav
Copy link

javierav commented Mar 4, 2024

@sandstrom @icy-arctic-fox I have also detected this and had planned to fix it in a PR, but which of the two methods is the correct one to make it stay?

@sandstrom
Copy link
Collaborator

They both do the same thing, but @groups[0] == 0xfe80 should be more performant.

I'd keep that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants