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
81
Can you trust your tests?
tadassce
0
42
Other Decks in Technology
See All in Technology
LLM評価の落とし穴~開発者目線で気をつけるポイント~
rishigami
11
3.2k
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
12
7.9k
QAエンジニアが伝えたい品質保証の羅針盤 / Compass for Quality Assurance
mii3king
1
330
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
15
36k
QA経験のないエンジニアリング マネージャーがQAのカジュアル面談に出て 苦労していること・気づいたこと / scrum fest niigata 2024
yoshikiiida
2
660
グイグイ系QAエンジニアでやっていくよ!
____rina____
0
760
DevRelによる信頼構築とデータ駆動で変わるエンジニア採用 / DevRel Trust Building to Data Driven Engineering Hiring
bobtani
1
130
RailsConf 2024 Keynote "Startups on Rails in 2024"
irinanazarova
0
800
.NET GraphQL Client のリアル
sansantech
PRO
1
250
TailwindCSSでUIライブラリを作る際のハマりどころ
shuta13
0
230
技術力の伸ばし方を考える
khirata
0
140
【TSkaigi】2024/05/11 当日スライド
kimitashoichi
14
4k
Featured
See All Featured
Producing Creativity
orderedlist
PRO
338
39k
The Cult of Friendly URLs
andyhume
74
5.7k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
123
39k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
8
3.5k
Optimising Largest Contentful Paint
csswizardry
13
2.4k
It's Worth the Effort
3n
180
27k
Clear Off the Table
cherdarchuk
86
310k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
26
2.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
21
2k
YesSQL, Process and Tooling at Scale
rocio
165
13k
How GitHub (no longer) Works
holman
305
140k
Embracing the Ebb and Flow
colly
80
4.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 ]