21
loading...
This website collects cookies to deliver better user experience
an_array = [1, 'two', 3.0]
an_array[1]
two
an_array[3]
nil
an_array[-1]
3.0
an_array[-3]
1
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
letters[2..5]
['c', 'd', 'e', 'f']
Ranges
are a basic Ruby type.letters[5..]
['f, 'g', 'h', 'i', 'j']
letters.length
10
letters.empty?
false
letters.sort
["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
letters.reverse
["j", "i", "h", "g", "f", "e", "d", "c", "b", "a"]
letters.min
"a"
letters.max
"j"
letters.methods
[:to_h, :include?, :&, :*, :+, :-,
:at, :fetch, :last, :union, :difference, :intersection,
:push, :append, :pop, :shift, :unshift, :each_index, :join,
:rotate, :rotate!, :sort!, :sort_by!, :collect!, :map!,
:select!, :filter!, :keep_if, :values_at, :delete_at,
:delete_if, :reject!, :transpose, :fill, :assoc, :rassoc,
:uniq!, :compact, :compact!, :flatten, :flatten!, :shuffle!,
:shuffle, :sample, :permutation, :combination,
:repeated_permutation, :repeated_combination, :product,
:bsearch, :sort, :bsearch_index, :deconstruct, :count,
:find_index, :select, :filter, :reject, :collect, :map,
:first, :all?, :any?, :one?, :none?, :minmax, :|,
:reverse_each, :zip, :take, :take_while, :drop, :<=>, :<<,
:cycle, :drop_while, :==, :sum, :uniq, :[], :[]=, :insert,
:empty?, :eql?, :index, :rindex, :replace, :clear, :max,
:min, :inspect, :length, :size, :each, :reverse, :concat,
:prepend, :reverse!, :to_ary, :to_a, :to_s, :pack, :delete,
:slice, :slice!, :dig, :hash, :each_slice, :each_cons,
:each_with_object, :chunk, :slice_before, :slice_after,
:slice_when, :chunk_while, :to_set, :chain, :lazy, :find,
:entries, :sort_by, :grep, :grep_v, :detect, :find_all,
:filter_map, :flat_map, :collect_concat, :inject, :reduce,
:partition, :group_by, :tally, :min_by, :max_by, :minmax_by,
:member?, :each_with_index, :each_entry, :dup, :itself,
:yield_self, :then, :taint, :tainted?, :untaint, :untrust,
:untrusted?, :trust, :frozen?, :methods, :singleton_methods,
:protected_methods, :private_methods, :public_methods,
:instance_variables, :instance_variable_get,
:instance_variable_set, :instance_variable_defined?,
:remove_instance_variable, :instance_of?, :kind_of?, :is_a?,
:tap, :class, :display, :singleton_class, :clone,
:public_send, :method, :public_method, :singleton_method,
:define_singleton_method, :extend, :to_enum, :enum_for,
:===, :=~, :!~, :nil?, :respond_to?, :freeze, :object_id,
:send, :__send__, :!, :!=, :__id__, :equal?, :instance_eval,
:instance_exec]