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
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
430
フルカイテン株式会社 採用資料
fullkaiten
0
40k
AWS Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
170
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
1
2.3k
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
Application Development WG Intro at AppDeveloperCon
salaboy
0
180
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
470
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
B2B SaaS × AI機能開発 〜テナント分離のパターン解説〜 / B2B SaaS x AI function development - Explanation of tenant separation pattern
oztick139
2
220
The Role of Developer Relations in AI Product Success.
giftojabu1
0
120
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Documentation Writing (for coders)
carmenintech
65
4.4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Bash Introduction
62gerente
608
210k
BBQ
matthewcrist
85
9.3k
How GitHub (no longer) Works
holman
310
140k
Faster Mobile Websites
deanohume
305
30k
The Invisible Side of Design
smashingmag
298
50k
Music & Morning Musume
bryan
46
6.2k
Thoughts on Productivity
jonyablonski
67
4.3k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
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 ]