123456789_123456789_123456789_123456789_123456789_

Class: HISTORY

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Enumerable
Inherits: Object
Defined in: ext/readline/readline.c

Class Attribute Summary

Class Method Summary

Class Attribute Details

.empty?Boolean (readonly)

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1839

static VALUE
hist_empty_p(VALUE self)
{
    return history_length == 0 ? Qtrue : Qfalse;
}

Class Method Details

.<<(str)

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1753

static VALUE
hist_push(VALUE self, VALUE str)
{
    OutputStringValue(str);
    add_history(RSTRING_PTR(str));
    return self;
}

.[](index)

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1710

static VALUE
hist_get(VALUE self, VALUE index)
{
    HIST_ENTRY *entry = NULL;
    int i;

    i = NUM2INT(index);
    if (i < 0) {
        i += history_length;
    }
    if (i >= 0) {
        entry = history_get(history_get_offset_func(i));
    }
    if (entry == NULL) {
        rb_raise(rb_eIndexError, "invalid index");
    }
    return rb_locale_str_new_cstr(entry->line);
}

.[]=(index, str)

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1730

static VALUE
hist_set(VALUE self, VALUE index, VALUE str)
{
    HIST_ENTRY *entry = NULL;
    int i;

    i = NUM2INT(index);
    OutputStringValue(str);
    if (i < 0) {
        i += history_length;
    }
    if (i >= 0) {
        entry = replace_history_entry(history_replace_offset_func(i), RSTRING_PTR(str), NULL);
    }
    if (entry == NULL) {
        rb_raise(rb_eIndexError, "invalid index");
    }
    return str;
}

.clear

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1860

static VALUE
hist_clear(VALUE self)
{
    clear_history();
    return self;
}

.delete_at(index)

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1845

static VALUE
hist_delete_at(VALUE self, VALUE index)
{
    int i;

    i = NUM2INT(index);
    if (i < 0)
        i += history_length;
    if (i < 0 || i > history_length - 1) {
        rb_raise(rb_eIndexError, "invalid index");
    }
    return rb_remove_history(i);
}

.each

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1816

static VALUE
hist_each(VALUE self)
{
    HIST_ENTRY *entry;
    int i;

    RETURN_ENUMERATOR(self, 0, 0);

    for (i = 0; i < history_length; i++) {
        entry = history_get(history_get_offset_func(i));
        if (entry == NULL)
            break;
        rb_yield(rb_locale_str_new_cstr(entry->line));
    }
    return self;
}

.length Also known as: .size

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1833

static VALUE
hist_length(VALUE self)
{
    return INT2NUM(history_length);
}

.pop

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1796

static VALUE
hist_pop(VALUE self)
{
    if (history_length > 0) {
        return rb_remove_history(history_length - 1);
    } else {
        return Qnil;
    }
}

.push(*args)

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1761

static VALUE
hist_push_method(int argc, VALUE *argv, VALUE self)
{
    VALUE str;

    while (argc--) {
        str = *argv++;
        OutputStringValue(str);
        add_history(RSTRING_PTR(str));
    }
    return self;
}

.shift

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1806

static VALUE
hist_shift(VALUE self)
{
    if (history_length > 0) {
        return rb_remove_history(0);
    } else {
        return Qnil;
    }
}

.size

Alias for .length.

.to_s

[ GitHub ]

  
# File 'ext/readline/readline.c', line 1692

static VALUE
hist_to_s(VALUE self)
{
    return rb_str_new_cstr("HISTORY");
}