Class: Cumo::NArray::Step

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/cumo/narray/step.c

Instance Method Summary collapse

Constructor Details

#new(start, end) ⇒ Object #new(range, step = nil, length = nil) ⇒ Object

Constructs a step using three parameters among start, end, step and length. start, end parameters can be replaced with range. If the step is omitted (or supplied with nil), then calculated from length or definded as 1.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'ext/cumo/narray/step.c', line 92

static VALUE
step_initialize( int argc, VALUE *argv, VALUE self )
{
    VALUE a, b=Qnil, c=Qnil, d=Qnil, e=Qnil;

    rb_scan_args(argc, argv, "13", &a, &b, &c, &d);
    /* Selfs are immutable, so that they should be initialized only once. */
    if (rb_ivar_defined(self, cumo_id_beg)) {
        rb_name_error(rb_intern("initialize"), "`initialize' called twice");
    }
    if (rb_obj_is_kind_of(a,rb_cRange)) {
        if (argc>3) {
            rb_raise(rb_eArgError, "extra argument");
        }
        d = c;
        c = b;
        e = rb_funcall(a, rb_intern("exclude_end?"), 0);
        //b = rb_ivar_get(a, cumo_id_end);
        b = rb_funcall(a, cumo_id_end, 0);
        //a = rb_ivar_get(a, cumo_id_beg);
        a = rb_funcall(a, cumo_id_beg, 0);
    }
    step_init(self, a, b, c, d, e);
    return Qnil;
}

Instance Method Details

#beginObject #firstObject

Returns the start of step.

Overloads:

  • #beginObject

    Returns:

    • (Object)
  • #firstObject

    Returns:

    • (Object)


126
127
128
129
130
# File 'ext/cumo/narray/step.c', line 126

static VALUE
step_first( VALUE self )
{
    return rb_ivar_get(self, cumo_id_beg);
}

#endObject #lastObject

Returns the object that defines the end of step.

Overloads:

  • #endObject

    Returns:

    • (Object)
  • #lastObject

    Returns:

    • (Object)


140
141
142
143
144
# File 'ext/cumo/narray/step.c', line 140

static VALUE
step_last( VALUE self )
{
    return rb_ivar_get(self, cumo_id_end);
}

#exclude_end?Boolean

Returns true if step excludes its end value.

Returns:

  • (Boolean)


179
180
181
182
183
# File 'ext/cumo/narray/step.c', line 179

static VALUE
step_exclude_end_p(VALUE self)
{
    return RTEST(rb_ivar_get(self, cumo_id_excl)) ? Qtrue : Qfalse;
}

#beginObject #firstObject

Returns the start of step.

Overloads:

  • #beginObject

    Returns:

    • (Object)
  • #firstObject

    Returns:

    • (Object)


126
127
128
129
130
# File 'ext/cumo/narray/step.c', line 126

static VALUE
step_first( VALUE self )
{
    return rb_ivar_get(self, cumo_id_beg);
}

#endObject #lastObject

Returns the object that defines the end of step.

Overloads:

  • #endObject

    Returns:

    • (Object)
  • #lastObject

    Returns:

    • (Object)


140
141
142
143
144
# File 'ext/cumo/narray/step.c', line 140

static VALUE
step_last( VALUE self )
{
    return rb_ivar_get(self, cumo_id_end);
}

#lengthObject #sizeObject

Returns the length of step.

Overloads:

  • #lengthObject

    Returns:

    • (Object)
  • #sizeObject

    Returns:

    • (Object)


154
155
156
157
158
# File 'ext/cumo/narray/step.c', line 154

static VALUE
step_length( VALUE self )
{
    return rb_ivar_get(self, cumo_id_len);
}

#lengthObject #sizeObject

Returns the length of step.

Overloads:

  • #lengthObject

    Returns:

    • (Object)
  • #sizeObject

    Returns:

    • (Object)


154
155
156
157
158
# File 'ext/cumo/narray/step.c', line 154

static VALUE
step_length( VALUE self )
{
    return rb_ivar_get(self, cumo_id_len);
}

#stepObject

Returns the step of step.

Returns:

  • (Object)


167
168
169
170
171
# File 'ext/cumo/narray/step.c', line 167

static VALUE
step_step( VALUE self )
{
    return rb_ivar_get(self, cumo_id_step);
}