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
85
Can you trust your tests?
tadassce
0
44
Other Decks in Technology
See All in Technology
地方拠点で エンジニアリングマネージャーってできるの? 〜地方という制約を楽しむオーナーシップとコミュニティ作り〜
1coin
1
230
白金鉱業Meetup Vol.17_あるデータサイエンティストのデータマネジメントとの向き合い方
brainpadpr
6
750
スタートアップ1人目QAエンジニアが QAチームを立ち上げ、“個”からチーム、 そして“組織”に成長するまで / How to set up QA team at reiwatravel
mii3king
2
1.5k
組織貢献をするフリーランスエンジニアという生き方
n_takehata
1
1.3k
2025-02-21 ゆるSRE勉強会 Enhancing SRE Using AI
yoshiiryo1
1
340
データマネジメントのトレードオフに立ち向かう
ikkimiyazaki
6
980
クラウドサービス事業者におけるOSS
tagomoris
1
770
PHPで印刷所に入稿できる名札データを作る / Generating Print-Ready Name Tag Data with PHP
tomzoh
0
100
次世代KYC活動報告 / 20250219-BizDay17-KYC-nextgen
oidfj
0
250
【Developers Summit 2025】プロダクトエンジニアから学ぶ、 ユーザーにより高い価値を届ける技術
niwatakeru
2
1.4k
Nekko Cloud、 これまでとこれから ~学生サークルが作る、 小さなクラウド
logica0419
2
970
偶然 × 行動で人生の可能性を広げよう / Serendipity × Action: Discover Your Possibilities
ar_tama
1
1.1k
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The World Runs on Bad Software
bkeepers
PRO
67
11k
Designing for humans not robots
tammielis
250
25k
Rails Girls Zürich Keynote
gr2m
94
13k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
240
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Cult of Friendly URLs
andyhume
78
6.2k
Making Projects Easy
brettharned
116
6k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
Side Projects
sachag
452
42k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
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 ]