Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Range.include? and Range.member? in Ruby

Ruby has a very useful Range class for expressing alphabetical and numerical ranges.

There are two methods on this class that I can't seem to distinguish between:
Range.include? and Range.member?

Ruby-doc.org gives exactly the same description for both.

What are the differences between them, if any?

like image 285
Marco Prins Avatar asked Dec 26 '22 09:12

Marco Prins


2 Answers

They are aliases of each other. If you expand the source code in the docs you see they both refer to the same internal function.

like image 95
thomthom Avatar answered Feb 04 '23 03:02

thomthom


Range.instance_method(:include?) == Range.instance_method(:member?)
#=> true
like image 22
MVP Avatar answered Feb 04 '23 02:02

MVP