Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby 101

Ruby 101

Basic ruby introduction for Railsgirls İstanbul 2018

033485f7e18823d4ccabb24e5cb4935f?s=128

Uğur Özyılmazel

November 24, 2018
Tweet

More Decks by Uğur Özyılmazel

Other Decks in Programming

Transcript

  1. None
  2. Uğur "vigo" Özyılmazel vigobronx vigo

  3. PROGRAMLAMA DİLİ

  4. None
  5. Ruby, programcıları mutlu etmek üzere tasarlanmıştır! - Matz

  6. TÜRKÇE BİLİYOR!

  7. şehirler = %w[İstanbul Ankara Viyana Paris] gittiğim_şehirler = %w[İstanbul Viyana]

    puts "Gitmem gereken şehirler", şehirler - gittiğim_şehirler Gitmem gereken şehirler Ankara Paris
  8. Herşey : nesne

  9. 5.class # => Integer 5.class.superclass # => Numeric 5.class.superclass.superclass #

    => Object 5.class.superclass.superclass.superclass # => BasicObject 5.class.superclass.superclass.superclass.superclass # => nil
  10. Integer Numeric Object Basic Object

  11. 5.methods # => [:- @, :**, :<=>, :upto, :<<, :<=,

    :>=, :==, :chr, :===, :>>, :[], : %, :&, :inspect, : +, :ord, :-, :/, :*, :size, :succ, :<, :>, :to_int, :coerce, :divmod, :to_ s, :to_i, :fdiv, :modulo, :remainder, :abs, :magnitude, :lcm, :integer?, : rationalize, :gcdlcm, :gcd, :denominator, :floor, :ceil, :round, :truncate , :to_r, :to_f, :^, :odd?, :even?, :allbits?, :anybits?, :nobits?, :downto , :times, :pred, :pow, :bit_length, :digits, :numerator, :next, :div, :|, :~, : +@, :conjugate, :eql?, :singleton_method_added, :i, :real?, :zero?, :nonze ro?, :finite?, :infinite?, :step, :positive?, :negative?, :angle, :real, : to_c, :conj, :phase, :imag, :abs2, :arg, :imaginary, :rectangular, :rect, :clone, :dup, :polar, :quo, :between?, :clamp, :instance_variable_set, :in stance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_ of?, :is_a?, :tap, :instance_variable_get, :public_methods, :instance_vari ables, :method, :public_method, :define_singleton_method, :singleton_metho d, :public_send, :extend, :pp, :to_enum, :enum_for, :=~, :! ~, :respond_to?, :freeze, :object_id, :send, :display, :nil?, :hash, :clas s, :singleton_class, :yield_self, :itself, :tainted?, :taint, :untrust, :u ntaint, :trust, :untrusted?, :methods, :frozen?, :singleton_methods, :prot ected_methods, :private_methods, :!, :equal?, :instance_eval, :instance_ex ec, :!=, :__id__, :__send__]
  12. TÜM SINIFLAR AÇIKTIR!

  13. class Integer def kere(n) self * n end end 5.kere(5)

    # => 25 5.kere(5).kere(2) # => 50
  14. class Integer def gün self * 24 * 60 *

    60 end def önce Time.now - self end def sonra Time.now + self end end Time.now # => 2018-11-23 14:42:23 +0300 5.gün.önce # => 2018-11-18 14:42:23 +0300 1.gün.sonra # => 2018-11-24 14:42:23 +0300
  15. konuşma dİlİne benzer

  16. 5.times do |i| puts "Ruby’i seviyorum, i = #{i}" if

    i > 2 end # Ruby’i seviyorum, i = 3 # Ruby’i seviyorum, i = 4
  17. meals = %w[Pizza Döner Kebab] print "Let’s eat here!" unless

    meals.include? "Soup" menü'de çorba yoksa yemeğİ burada YİYELİM!
  18. varıable merhaba = "Dünya" # Değişken @merhaba # Instance Variable

    @@merhaba # Class Variable $merhaba # Global Variable MERHABA # Constant
  19. ARRAY [] # => [] [1, "Merhaba", 2] # =>

    [1, "Merhaba", 2] [[1, 2], ["Merhaba", "Dünya"]] # => [[1, 2], ["Merhaba", "Dünya"]]
  20. hash {} # => {} {:foo => "bar"} # =>

    {:foo=>"bar"} # Eski {foo: "bar"} # => {:foo=>"bar"} # Yeni
  21. parantez? def merhaba kullanıcı "Merhaba #{kullanıcı}" end merhaba "vigo" #

    => "Merhaba vigo"
  22. SORU İŞARETİ [].empty? # => true ["vigo", "ezel"].include? "vigo" #

    => true user.admin? # => false
  23. ÜNLEM İŞARETİ isim = "vigo" isim.reverse # => "ogiv" isim

    # => "vigo" isim.reverse! # => "ogiv" isim # => "ogiv"
  24. zİNCİRLEME METHODLAR "vigo".reverse.reverse # => "vigo" ["v", "i", "g", "o"].join.reverse.split(//).join.reverse

    # => "vigo"
  25. İterasyon [1, "merhaba", 2, "dünya"].each do |eleman| puts eleman end

    [1, "merhaba", 2, "dünya"].each {|eleman| puts eleman} # 1 # merhaba # 2 # dünya
  26. İterasyon [1, 2, 3, 4, 5].select{|number| number.even?} # => [2,

    4] [1, 2, 3, 4, 5].inject{|sum, number| sum + number} # => 15 [1, 2, 3, 4, 5].map{|number| number * 2} # => [2, 4, 6, 8, 10]
  27. class class Person attr_accessor :age end vigo = Person.new vigo

    # => #<Person:0x00007fef1693fe60> vigo.age = 46 vigo # => #<Person:0x00007fef1693fe60 @age=46> vigo.age # => 46
  28. class class Person attr_accessor :age # Getter & Setter def

    initialize(name) @name = name end def greet "Hello #{@name}" end end vigo = Person.new "Uğur" vigo.age = 46 vigo # => #<Person:0x00007f889b056c40 @name="Uğur", @age=46> vigo.greet # => "Hello Uğur"
  29. class class Person def initialize(name) @name = name end def

    age=(value) @age = value end def age @age end def greet "Hello #{@name}" end end vigo = Person.new "Uğur" vigo.age = 43 Getter Setter attr_accessor :age }
  30. class class Person def is_human? true end end class Cyborg

    < Person def is_human? false end end vigo = Person.new # => #<Person:0x007faa7291d268> vigo.is_human? # => true t800 = Cyborg.new # => #<Cyborg:0x007faa7291cbd8> t800.is_human? # => false
  31. module + MIXIN module Greeter def say_hello "Hello #{@name}" end

    end class Person include Greeter def initialize(name) @name = name end end vigo = Person.new "Uğur" vigo.say_hello # => "Hello Uğur"
  32. İLERİ SEVİYE KONULAR Meta Programming Monkey Patching Block & Proc

    & Lambda Functional Programming
  33. kaynaklar http://www.ruby-doc.org/ http://vigo.gitbooks.io/ruby-101/ http://tryruby.org/ http://rubykoans.com/ https://rubymonk.com/ https://www.ruby-lang.org/en/documentation/quickstart/ https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/