BogoToBogo
  • Home
  • About
  • Big Data
  • Machine Learning
  • AngularJS
  • Python
  • C++
  • go
  • DevOps
  • Kubernetes
  • Algorithms
  • More...
    • Qt 5
    • Linux
    • FFmpeg
    • Matlab
    • Django 1.8
    • Ruby On Rails
    • HTML5 & CSS

Ruby Arrays 2020

RubyOnRails_logo




Bookmark and Share





bogotobogo.com site search:




Ruby Arrays

Ruby arrays are ordered, integer-indexed collections of any object. Each element in an array is associated with and referred to by an index.

Ruby arrays can hold objects such as String, Integer, Fixnum, Hash, Symbol, even other Array objects. Ruby arrays are not as rigid as arrays in other languages. Ruby arrays grow automatically while adding elements to them.

One way of creating an array is with the new class method:

array_1 = Array.new

We can set the size of an array at the time of creating array:

array_2 = Array.new(3) #=> [nil, nil, nil]

We can assign a value to each element in the array as follows:

array_3 = Array.new(3, "Ruby") #=> ["Ruby", "Ruby", "Ruby"]





Binary search

As a practice, here is a code for binary search:

#!/usr/bin/ruby
# bin.rb

def bin(a,n)
   s = 0
   e = a.length - 1
   mid = (s + e)/2
   while ( mid >= s and mid <= e)
      if (n < a[mid])
         e = mid - 1
      elsif (n > a[mid])
         s = mid + 1
      else
         return true
      end
      mid = (s + e)/2
   end
   return false
end

# input
arr = [1,3,5,7,9,11,13,15,17,19]

# try
find = [1,9,17,0,21,8]

find.each do |item|
   puts bin(arr,item)
end

Output:

true
true
true
false
false
false



Ruby on Rails

  • Ruby On Rails Home
  • Ruby - Input/Output, Objects, Load
  • Ruby - Condition (if), Operators (comparison/logical) & case statement
  • Ruby - loop, while, until, for, each, (..)
  • Ruby - Functions
  • Ruby - Exceptions (raise/rescue)
  • Ruby - Strings (single quote vs double quote, multiline string - EOM, concatenation, substring, include, index, strip, justification, chop, chomp, split)
  • Ruby - Class and Instance Variables
  • Ruby - Class and Instance Variables II
  • Ruby - Modules
  • Ruby - Iterator : each
  • Ruby - Symbols (:)
  • Ruby - Hashes (aka associative arrays, maps, or dictionaries)
  • Ruby - Arrays
  • Ruby - Enumerables
  • Ruby - Filess
  • Ruby - code blocks and yield
  • Rails - Embedded Ruby (ERb) and Rails html
  • Rails - Partial template
  • Rails - HTML Helpers (link_to, imag_tag, and form_for)
  • Layouts and Rendering I - yield, content_for, content_for?
  • Layouts and Rendering II - asset tag helpers, stylesheet_link_tag, javascript_include_tag
  • Rails Project
  • Rails - Hello World
  • Rails - MVC and ActionController
  • Rails - Parameters (hash, array, JSON, routing, and strong parameter)
  • Filters and controller actions - before_action, skip_before_action
  • The simplest app - Rails default page on a Shared Host
  • Redmine Install on a Shared Host
  • Git and BitBucket
  • Deploying Rails 4 to Heroku
  • Scaffold: A quickest way of building a blog with posts and comments
  • Databases and migration
  • Active Record
  • Microblog 1
  • Microblog 2
  • Microblog 3 (Users resource)
  • Microblog 4 (Microposts resource I)
  • Microblog 5 (Microposts resource II)
  • Simple_app I - rails html pages
  • Simple_app II - TDD (Home/Help page)
  • Simple_app III - TDD (About page)
  • Simple_app IV - TDD (Dynamic Pages)
  • Simple_app V - TDD (Dynamic Pages - Embedded Ruby)
  • Simple_app VI - TDD (Dynamic Pages - Embedded Ruby, Layouts)
  • App : Facebook and Twitter Authentication using Omniauth oauth2
  • Authentication and sending confirmation email using Devise
  • Adding custom fields to Devise User model and Customization
  • Devise Customization 2. views/users
  • Rails Heroku Deploy - Authentication and sending confirmation email using Devise
  • Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger I
  • Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger II
  • OOPS! Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger (Trouble shooting)







Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization

YouTubeMy YouTube channel

Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong






Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







Ruby on Rails



Ruby On Rails Home

Ruby - Input/Output, Objects, Load

Ruby - Condition (if), Operators (comparison/logical) & case statement

Ruby - loop, while, until, for, each, (..)

Ruby - Functions

Ruby - Exceptions (raise/rescue)

Ruby - Strings (single quote vs double quote, multiline string - EOM, concatenation, substring, include, index, strip, justification, chop, chomp, split)

Ruby - Class and Instance Variables

Ruby - Class and Instance Variables II

Ruby - Modules

Ruby - Iterator : each

Ruby - Symbols (:)

Ruby - Hashes (aka associative arrays, maps, or dictionaries)

Ruby - Arrays

Ruby - Enumerables

Ruby - Filess

Ruby - code blocks and yield

Rails - Embedded Ruby (ERb) and Rails html

Rails - Partial template

Rails - HTML Helpers (link_to, imag_tag, and form_for)

Layouts and Rendering I - yield, content_for, content_for?

Layouts and Rendering II - asset tag helpers, stylesheet_link_tag, javascript_include_tag

Rails Project

Rails - Hello World

Rails - MVC and ActionController

Rails - Parameters (hash, array, JSON, routing, and strong parameter)

Filters and controller actions - before_action, skip_before_action

The simplest app - Rails default page on a Shared Host

Redmine Install on a Shared Host

Git and BitBucket

Deploying Rails 4 to Heroku

Scaffold: A quickest way of building a blog with posts and comments

Databases and migration

Active Record

Microblog 1

Microblog 2

Microblog 3 (Users resource)

Microblog 4 (Microposts resource I)

Microblog 5 (Microposts resource II)

Simple_app I - rails html pages

Simple_app II - TDD (Home/Help page)

Simple_app III - TDD (About page)

Simple_app IV - TDD (Dynamic Pages)

Simple_app V - TDD (Dynamic Pages - Embedded Ruby)

Simple_app VI - TDD (Dynamic Pages - Embedded Ruby, Layouts)

App : Facebook and Twitter Authentication using Omniauth oauth2

Authentication and sending confirmation email using Devise

Adding custom fields to Devise User model and Customization

Devise Customization 2. views/users

Rails Heroku Deploy - Authentication and sending confirmation email using Devise

Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger I

Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger II

OOPS! Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger (Trouble shooting)











Contact

BogoToBogo
contactus@bogotobogo.com

Follow Bogotobogo

About Us

contactus@bogotobogo.com

YouTubeMy YouTube channel
Pacific Ave, San Francisco, CA 94115

Pacific Ave, San Francisco, CA 94115

Copyright © 2024, bogotobogo
Design: Web Master