Ruby 实施定制;封面-基于方法

Ruby 实施定制;封面-基于方法,ruby,range,Ruby,Range,如何实现自定义方法“cover_e?”它的实现几乎与标准类似 覆盖范围(val) 如果obj在范围的开始和结束之间,则返回true ("a".."z").cover?("c") #=> true 自定义方法应使用“嵌套”/“继承”范围,如:((2..5)) 谢谢 class Range def cover_e? rng rng.minmax.all?{|i| self.include? i} end end p (1..10).cover_e?((2..5)) p

如何实现自定义方法“cover_e?”它的实现几乎与标准类似 覆盖范围(val) 如果obj在范围的开始和结束之间,则返回true

 ("a".."z").cover?("c")    #=> true
自定义方法应使用“嵌套”/“继承”范围,如:((2..5))

谢谢

class Range
  def cover_e? rng
    rng.minmax.all?{|i| self.include? i}
  end
end
p (1..10).cover_e?((2..5))
p (5..15).cover_e?((10..20))
# >> true
# >> false


所有已知的感激之词都已用于Priti。Спасибо!所有已知的感激之词都已用于Priti。Спасибо!
class Range
  def cover_e? rng
    rng.minmax.all?{|i| self.include? i}
  end
end
p (1..10).cover_e?((2..5))
p (5..15).cover_e?((10..20))
# >> true
# >> false
class Range
  def cover_e? rng
    (rng.to_a | self.to_a).size == self.size
  end
end
p (1..10).cover_e?((2..5))
p (5..15).cover_e?((10..20))
# >> true
# >> false
class Range
  def cover_e? other
    cover?(other.min) and cover?(other.max)
  end
end