Ruby Files 2020
bogotobogo.com site search:
Ruby Files
The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection.
The following example shows the use of enumerable:
#!/usr/bin/ruby # fl.rb file = File.new("particles.out","w") file.puts "Quarks" file.puts "Leptons" file.puts "Gluons" file.puts "Photon" file.puts "Z Boson" file.close puts File.read("particles.out") puts file = File.new("particles.out","a") file.puts "W Boson" file.puts "Higgs" file.close puts File.read("particles.out")
Output:
Quarks Leptons Gluons Photon Z Boson Quarks Leptons Gluons Photon Z Boson W Boson Higgs
Ruby Files - looping lines & split
We'll read files, and looping through each line. Then, we split the line with ', and put each item into an output as variables.
#!/usr/bin/ruby # fl2.rb file = File.new("particles_info.out","w") file.puts "Quarks,2,3,pair,3,36" file.puts "Leptons,2,3,pair,None,12" file.puts "Gluons,1,1,own,8,8" file.puts "Photon,1,1,own,None,1" file.puts "Z Boson,1,1,own,None,1" file.puts "W Boson,1,1,pair,None,2" file.puts "Higgs,1,1,own,None,1" file.close puts File.read("particles_info.out") puts File.open("particles_info.out") do |record| record.each do |item| name, types, generations, antiparticle, colors, total = item.split(',') puts "Particle #{name} is type of #{types}. It has #{generations} generations, #{antiparticle} antiparticles with #{colors}. Totals = #{total}" end end
Output:
Quarks,2,3,pair,3,36 Leptons,2,3,pair,None,12 Gluons,1,1,own,8,8 Photon,1,1,own,None,1 Z Boson,1,1,own,None,1 W Boson,1,1,pair,None,2 Higgs,1,1,own,None,1 Particle Quarks is type of 2. It has 3 generations, pair antiparticles with 3. Totals = 36 Particle Leptons is type of 2. It has 3 generations, pair antiparticles with None. Totals = 12 Particle Gluons is type of 1. It has 1 generations, own antiparticles with 8. Totals = 8 Particle Photon is type of 1. It has 1 generations, own antiparticles with None. Totals = 1 Particle Z Boson is type of 1. It has 1 generations, own antiparticles with None. Totals = 1 Particle W Boson is type of 1. It has 1 generations, pair antiparticles with None. Totals = 2 Particle Higgs is type of 1. It has 1 generations, own antiparticles with None. Totals = 1
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