Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ruby for Starter
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
高見龍
March 23, 2013
Programming
480
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ruby for Starter
高見龍
March 23, 2013
More Decks by 高見龍
See All by 高見龍
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
630
自己的售票系統自己做!
eddie
0
640
AI Agent 時代的開發者生存指南
eddie
4
2.8k
print("Hello, World")
eddie
2
670
為你自己學 Python - 冷知識篇
eddie
1
480
為你自己學 Python
eddie
0
780
Generative AI 年會小聚 - AI 教我寫程式
eddie
0
240
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
790
AI 時代的程式語言學習法
eddie
0
290
Other Decks in Programming
See All in Programming
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
210
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
510
源内ハンズオン概要編
hideg
0
170
170k Jobs a Day on GKE: Scaling Mercari's CI Platform - and What's Next for AI-Native Development
junyaokabe
0
110
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
130
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.8k
Building a Meta Ray-Ban display app
akkeylab
0
130
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
780
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
680
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
160
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
400
Go 1.27 における memory allocation の高速化
andpad
0
160
Featured
See All Featured
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
460
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
490
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
41k
ラッコキーワード サービス紹介資料
rakko
1
4.3M
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
640
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
360
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Accessibility Awareness
sabderemane
1
170
Google's AI Overviews - The New Search
badams
0
1.1k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
610
Evolving SEO for Evolving Search Engines
ryanjones
0
250
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
Transcript
Ruby Starter eddie@fju
None
current status
80% iOS app, 20% Ruby/Rails
What I want?
Problem Solving
History
まつもと ゆきひろ (Matz)
first released at 1995
2.0 released at 2013
None
Why Ruby? free, open source, easy to learn
Ruby != Rails
Happy, and Fun
Rubies CRuby(MRI), REE, mRuby, JRuby, IronRuby, Rubinius..etc
Version 1.8, 1.9, 2.0
Ruby 1.8 has no future
RVM Ruby Version Manager https://rvm.io/
Editors Vim, Emacs, TextMate, Sublime Text... etc
git
coding style https://github.com/styleguide/ruby
Variables and Constants
local variable variable
global variable $variable
instance variable @variable
class variable @@variable
virtual variable true, false, self, nil
variable assignment a = 1 x, y, z = 1,
2, 3
Constant begins with a capital letter, and it can be
changed
Reserved word and Keyword
Logic and Flow Control
only false and nil are false
true v.s. TrueClass false v.s. FalseClass nil v.s. NilClass
if..elsif..end
unless = if not
if modifier
case .. when..
BEGIN{} and END{}
a = true ? 'a' : 'b'
a ||= 'a'
Comment # single line
Comment =begin .. =end
Loop and Iteration
for.. in..
while .. end
until .. end
until = while not
times
upto, downto
each, each_with_index
Block
Proc
my_square = Proc.new { | x | x ** 2
} my_square.call(10) # 100 my_square[10] # 100
lambda, ->
my_lambda = lambda { | x | x ** 2
} # new style in 1.9 my_lambda = -> x { x ** 2 } # how to call a lambda? my_lambda.call(10) my_lambda[10]
Proc v.s. lambda
def proc_test puts "hello" my_proc = Proc.new { return 1
} my_proc.call puts "ruby" end def lambda_test puts "hello" my_lambda = lambda { return 1 } my_lambda.call puts "ruby" end
{} v.s. do..end http://blog.eddie.com.tw/2011/06/03/do-end-vs-braces/
Number
Fixnum and Bignum
10 / 3
String http://ruby-doc.org/core-1.9.2/String.html
single and double quotes
%q v.s. %Q
"%s" % "eddie"
string interpolation
Array http://ruby-doc.org/core-1.9.2/Array.html
Array.new v.s. []
%w
Hash http://ruby-doc.org/core-1.9.2/Hash.html
Hash.new v.s {}
a = { :name => 'eddie' } a = {
name: 'eddie' }
Range http://ruby-doc.org/core-1.9.2/Range.html
(1..10) v.s. (1...10)
Methods
def method_name(param) ... end
parentheses can be omitted
? and !
return value
Singleton Method
class Cat def walk puts "I'm walking" end end cat
= Cat.new def cat.fly puts "I can fly" end cat.fly
Method Missing
def method_missing(method_name) puts "method: #{method_name} is called!" end [1, 2,
3, 4].hello
Exception Handling begin .. rescue.. else.. ensure.. end
def open_my_file(file_name) File.open file_name do |f| puts f.read end end
begin open_my_file("block_demo.r") rescue => e puts e else puts "it's working good!" ensure puts "this must be executed, no matter what" end
Object-Oriented Programming
everything in Ruby is an Object
object = state+ behavior
top class = Object top class would be BasicObject in
Ruby 1.9
class ClassName < ParentClass ... end
Naming Convention
initialize
ClassName.new
self = current object
instance and class variable
instance and class method
public, protected and private method
getter and setter
attr_reader, attr_writer and attr_accessor
Open Class
Module
module ModuleName ... end
module has no inheritance
module has no instance
Naming Convention
require v.s. load
Mixin
Ruby is single inheritance
Duck Typing
include v.s. extend
Gem
gem install PACKAGE_NAME
gem env
Bundle
Gemfile
gem "nokogiri", :git => "git://github.com/tenderlove/nokogiri.git" gem "secret_gem", :path => "~/my_secret_path"
bundle install
pack your own gem!
1. bundle gem NEW_NAME 2. gem build NEW_NAME.gemspec 3. gem
push NEW_NAME.gem http://docs.rubygems.org/read/chapter/20
Rake
Ruby Object Model