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
Search
Tadas Sce
March 01, 2014
Technology
4
140
Ruby
For non-rubyists
Tadas Sce
March 01, 2014
Tweet
Share
More Decks by Tadas Sce
See All by Tadas Sce
Can you trust your tests?
tadassce
0
83
Can you trust your tests?
tadassce
0
43
Other Decks in Technology
See All in Technology
Google Cloud で始める Cloud Run 〜AWSとの比較と実例デモで解説〜
risatube
PRO
0
120
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
1
4.8k
C++26 エラー性動作
faithandbrave
2
840
3年でバックエンドエンジニアが5倍に増えても破綻しなかったアーキテクチャ そして、これから / Software architecture that scales even with a 5x increase in backend engineers in 3 years
euglena1215
11
4k
[JAWS-UG新潟#20] re:Invent2024 -CloudOperationsアップデートについて-
shintaro_fukatsu
0
130
ハイテク休憩
sat
PRO
2
190
ZOZOTOWN の推薦における KPI モニタリング/KPI monitoring for ZOZOTOWN recommendations
rayuron
1
170
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
410
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
200
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
200
.NET 9 のパフォーマンス改善
nenonaninu
0
1.7k
AI×医用画像の現状と可能性_2024年版/AI×medical_imaging_in_japan_2024
tdys13
0
430
Featured
See All Featured
Being A Developer After 40
akosma
89
590k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
50k
Producing Creativity
orderedlist
PRO
342
39k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Facilitating Awesome Meetings
lara
50
6.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
300
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
18
2.3k
Code Review Best Practice
trishagee
65
17k
Designing for Performance
lara
604
68k
Documentation Writing (for coders)
carmenintech
67
4.5k
The Invisible Side of Design
smashingmag
299
50k
Transcript
{ title: Ruby, for: "non-rubyists", by: "Tadas Ščerbinskas" }
class Ruby def what? "A dynamic, open source programming language
" + "with a focus on simplicity and productivity. " + "It has an elegant syntax that is " + "natural to read and easy to write." end end
class Ruby def what_for? { web: ["Rails", "Sinatra", "Padrino"], desktop:
["MacRuby", "IronRuby"], mobile: ["RubyMotion", "MobiRuby", "Ruboto"] } end end
# Basics ! puts "Hello VilniusRB!" # => nil #
>> Hello VilniusRB! ! "Hi".class # => String 1.class # => Fixnum nil.class # => NilClass
# Numbers ! -4 # => -4 1.5 # =>
1.5 12.3e-3 # => 0.0123 0b101 # => 5 (bin) 0x11 # => 17 (hex) 020 # => 16 (oct) 12_000 # => 12000 10**20 # => 100000000000000000000
# Numbers ! -4.class # => Fixnum 1.5.class # =>
Float 12.3e-3.class # => Float 0b101.class # => Fixnum 0x11.class # => Fixnum 020.class # => Fixnum 12_000.class # => Fixnum (10**20).class # => Bignum
# Numbers ! 4.even? # => true 3.zero? # =>
false 3.next # => 4 ! 3.times do print "Hello " end ! # >> Hello Hello Hello
# Numbers ! 2 + 2 # => 4 !
2.+(2)
# Strings and symbols ! "foo #{1 + 2}" #
=> "foo 3" 'foo #{1 + 2}' # => "foo \#{1 + 2}" ! :foo # => :foo ! "foo".object_id == "foo".object_id # => false :foo.object_id == :foo.object_id # => true
# Strings and symbols ! "stressed".reverse # => "desserts" "vilnius".capitalize
# => "Vilnius" "patience".length # => 8 " nu ".strip # => "nu" "Lietuva".start_with? "Liet" # => true :ruby.upcase # => :RUBY
# Strings and symbols ! "I like coffee".sub("coffee", "beer") #
=> "I like beer" ! s = "I really really like ruby" s.split.count("really") # => 2
# Collections ! [1, 2, 3] # Array ! 1..10
# Range ! { :foo => 11, :bar => 12 } # Hash ! { foo: 11, bar: 12 } # Hash
# Collections ! cities = %w[London Oslo Paris Amsterdam Berlin]
visited = %w[Berlin Oslo] puts "I still need to visit: ", cities - visited ! # >> I still need to visit: # >> London # >> Paris # >> Amsterdam
# Collections ! (1..10).select(&:even?) # => [2, 4, 6, 8,
10] ! ["Tom", "Jerry"].join "&" # => "Tom&Jerry" ! [1, 2, 3].shuffle # => [3, 1, 2] ! [1, 1, 2, 1, 2].uniq # => [1, 2] ! [1, 2, 3].include?(2) # => true
# Variables ! monster # is a local variable !
Monster # is a constant ! @monster # is an instance variable ! @@monster # is a class variable ! $monster # is a global variable
# Variables ! a, b, c = 1, 2, 3
! a, b = b, a
# Conditionals ! puts "Hello" if monster.has_ears? ! puts "Hello"
unless monster.asleep?
# Conditionals ! if monster.big? puts "AAaah! run!!" elsif monster.medium?
puts "Be careful" else puts "Don't sweat it" end
# Conditionals ! case monster.size when :big puts "AAaah! run!!"
when :medium puts "Be careful" else puts "Don't sweat it" end
# Conditionals ! case monster.size when :big then puts "AAaah!
run!!" when :medium then puts "Be careful" else puts "Don't sweat it" end
# Blocks ! names = %w[Emily Eva Mia] names.each do
|name| puts "Hi #{name}!" end ! # >> Hi Emily! # >> Hi Eva! # >> Hi Mia!
# Blocks ! names = %w[Emily Eva Mia] names.each {
|name| puts "Hi #{name}!" } ! ! ! # >> Hi Emily! # >> Hi Eva! # >> Hi Mia!
# Blocks ! def with_time puts "Started at #{Time.now}" yield
puts "Finished at #{Time.now}" end ! with_time { sleep 2 } ! # >> Started at 2014-03-01 00:50:19 +0200 # >> Finished at 2014-03-01 00:50:21 +0200
class Monster def initialize(name) @name = name end end
module Tail def wiggle puts "wiggling" end end ! class
Monster include Tail end ! Monster.new("Swamp Donkey").wiggle
# Monkey patching ! 2 + 2 # => 4
! class Fixnum def +(x) 42 end end ! 2 + 2 # => 42
# Refinements ! module Evil refine Fixnum do def +(x)
42 end end end
# Refinements ! 2 + 2 # => 4 !
using Evil ! 2 + 2 # => 42
# Meta-programming class Shape attr_reader :dimensions ! def initialize(dimensions =
{}) @dimensions = dimensions end ! def width dimensions[:width] end ! def height dimensions[:height] end end
# Meta-programming class Shape attr_reader :dimensions ! def initialize(dimensions =
{}) @dimensions = dimensions end ! [:width, :height].each do |dim| define_method(dim) do dimensions[dim] end end end
# Thank you ! ! { name: "Tadas Ščerbinskas", email:
"
[email protected]
", twitter: "tadassce", github: "tadassce" }
# Užduotis ! # Sukurkite Template klasę, turinčią body #
metodą, kuri grąžins HTML'ą su paduotu # turiniu viduje.
references = %w[ https://www.ruby-lang.org http://en.wikipedia.org/wiki/Ruby_(programming_language) https://speakerdeck.com/davidfrancisco/learning-ruby ]