Posts

Showing posts from September, 2019

graphs

gem chartkick <%= area_chart @orders.group_by_day() { |order| order.created_at }.map { |date, orders| [date, orders.size] } %>

Array

Ruby Arrays: Insert, Append, Length, Index, Remove In this tutorial, we will cover: How to create a Ruby array How to access Elements How to add elements to a list How to delete elements from a list Create a Ruby Array Arrays can be created in various ways. All you need is a variable name. The first two examples  instantiate an array  in the letters variable. Take note that they won’t have any values. Arrays can be created by getting an instance of the Array class. 2.0.0-p0 :002 > letters = Array.new => [] A nice shortcut for this is to just give the value of  [] . 2.0.0-p0 :003 > letters = [] => [] Most of the time, we would like to have values in arrays we create. Here’s a very simple example on how to do it. 2.0.0-p0 :006 > letters = Array.new(['a', 'b']) => ["a", "b"] Again, there’s a shortcut. 2.0.0-p0 :001 > letters = ['a', 'b', 'c'] => ["a", ...