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
80
Can you trust your tests?
tadassce
0
40
Other Decks in Technology
See All in Technology
XRミーティング 2024-03-20
1ftseabass
PRO
0
100
中央集権体制からDataOpsへの転換 / centralized-to-dataops-transformation
pei0804
7
1.5k
任意コード実行の原理
ffri
0
180
8週連続ウェビナー_イチから学ぶFivetran
cmsuzu
0
170
LLM + RAG を使った SORACOM Support Bot の裏側の歴史
soracom
PRO
1
640
ビジネスとコード品質の接合点 そしてコード品質がそこに及ぼす影響 / The Intersections of Business and Engineering, and The Impact of Code Quality There
mtx2s
10
1k
ハイパフォーマンスな組織をつくるための開発生産性の考え方 / developer-productivity-high-performer-link-and-motivation
lmi
3
270
実務への応用例から考える 変更に強いオブジェクト指向設計 / 20240324-ooc2024
bengo4com
7
5.5k
Kubeflow Pipelines v2 で変わる機械学習パイプライン開発
asei
4
340
エンジニア候補者向け資料2024.03.28.pdf
macloud
0
2.9k
GitHub最新情報キャッチアップ 2024年3月
dzeyelid
17
3.2k
エンジニアブランディングチームの KPI / KPI's of engineer branding team
chaspy
1
140
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
501
110k
Facilitating Awesome Meetings
lara
39
5.5k
How to name files
jennybc
62
92k
4 Signs Your Business is Dying
shpigford
174
21k
Designing the Hi-DPI Web
ddemaree
275
33k
Adopting Sorbet at Scale
ufuk
66
8.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
657
120k
VelocityConf: Rendering Performance Case Studies
addyosmani
319
23k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
111
35k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
5
1.4k
We Have a Design System, Now What?
morganepeng
42
6.7k
Fireside Chat
paigeccino
19
2.6k
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 ]