Class: Range

Inherits:
Object show all
Defined in:
lib/primitive_wrapper.rb,
lib/primitive_wrapper.rb

Overview

if it makes sense, add methods here

Instance Method Summary collapse

Instance Method Details

#element_classObject



113
114
115
# File 'lib/primitive_wrapper.rb', line 113

def element_class
  return first.class
end

#reorderObject



96
97
98
99
100
101
102
# File 'lib/primitive_wrapper.rb', line 96

def reorder
  if exclude_end?
    last < first ? reverse : (first...last)
  else
    last < first ? reverse : (first..last)
  end
end

#reverseObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/primitive_wrapper.rb', line 85

def reverse
  if exclude_end?
    if (first==last)
      (last...first)
    else
      ((last.pred)..first)
    end
  else
    (last..first)
  end    
end

#reversed?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/primitive_wrapper.rb', line 79

def reversed? 
  first > last
end

#simple?Boolean

Returns:

  • (Boolean)


116
117
118
119
120
121
122
# File 'lib/primitive_wrapper.rb', line 116

def simple?
  return true if first.type_of? Integer
  if first.type_of? String
    return true if first.length==1
  end
  false
end

#simplifyObject



106
107
108
109
110
111
112
# File 'lib/primitive_wrapper.rb', line 106

def simplify
  if exclude_end?
    return (first...last) if first==last
    return (first..last.pred)
  end
  return (first..last)
end

#to_xrObject



82
83
84
# File 'lib/primitive_wrapper.rb', line 82

def to_xr
  XRange.new self
end

#~Object



67
68
69
# File 'lib/primitive_wrapper.rb', line 67

def ~
  self
end