Ruby'i Tanıyalım

Ruby'i Tanıyalım

17 OCAK RUBY VE RUBY ON RAİLS İLE TANIŞMA ETKİNLİĞİ için yapmış olduğum Ruby tanıtım sunumu.

033485f7e18823d4ccabb24e5cb4935f?s=128

Uğur Özyılmazel

January 17, 2015
Tweet

Transcript

  1. 1.
  2. 5.
  3. 7.
  4. 9.

    ş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
  5. 13.

    5.class # => Fixnum 5.class.superclass # => Integer 5.class.superclass.superclass #

    => Numeric 5.class.superclass.superclass.superclass # => Object 5.class.superclass.superclass.superclass.superclass # => BasicObject
  6. 15.

    5.methods # => [:to_s, :inspect, :-@, :+, :-, :*, :/,

    :div, : %, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===, :<=>, : >, :>=, :<, :<=, :~, :&, :|, :^, : [], :<<, :>>, :to_f, :size, :bit_length, :zero?, :odd?, :even?, :succ , :integer?, :upto, :downto, :times, :next, :pred, :chr, :ord, :to_i, :to_int, :floor, :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :nume rator, :denominator, :to_r, :rationalize, :singleton_method_added, :c oerce, :i, : +@, :eql?, :remainder, :real?, :nonzero?, :step, :quo, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, :conj, :between?, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust , :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_method s, :protected_methods, :private_methods, :public_methods, :instance_v ariables, :instance_variable_get, :instance_variable_set, :instance_v ariable_defined?, :remove_instance_variable, :instance_of?, :kind_of? , :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :! =, :instance_eval, :instance_exec, :__send__, :__id__]
  7. 17.

    class Fixnum def kere(n) self * n end end 5.kere(5)

    # => 25 5.kere(5).kere(2) # => 50
  8. 18.

    class Fixnum def gün self * 24 * 60 *

    60 end def önce Time.now - self end def sonra Time.now + self end end Time.now # => 2015-01-12 12:30:37 +0200 5.gün.önce # => 2015-01-07 12:30:37 +0200 1.gün.sonra # => 2015-01-13 12:30:37 +0200
  9. 19.
  10. 21.

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

    i > 2 end # Ruby’i seviyorum, i = 3 # Ruby’i seviyorum, i = 4
  11. 22.

    meals = %w[Pizza Döner Kebab] print "Let’s eat here!" unless

    meals.include? "Soup" menü'de çorba yoksa yemeğİ burada YİYELİM!
  12. 23.
  13. 24.

    varıable merhaba = "Dünya" # Değişken @merhaba # Instance Variable

    @@merhaba # Class Variable $merhaba # Global Variable MERHABA # Constant
  14. 25.

    ARRAY [] # => [] [1, "Merhaba", 2] # =>

    [1, "Merhaba", 2] [[1, 2], ["Merhaba", "Dünya"]] # => [[1, 2], ["Merhaba", "Dünya"]]
  15. 26.

    hash {} # => {} {:foo => "bar"} # =>

    {:foo=>"bar"} # Eski {foo: "bar"} # => {:foo=>"bar"} # Yeni
  16. 29.

    ÜNLEM İŞARETİ isim = "vigo" isim.reverse # => "ogiv" isim

    # => "vigo" isim.reverse! # => "ogiv" isim # => "ogiv"
  17. 31.

    İ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
  18. 32.

    İ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]
  19. 33.

    class class Person attr_accessor :age end vigo = Person.new vigo

    # => #<Person:0x007f98820e6ab0> vigo.age = 43 vigo # => #<Person:0x007f98820e6ab0 @age=43> vigo.age # => 43
  20. 34.

    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 = 43 vigo # => #<Person:0x007fc2810436c0 @name="Uğur", @age=43> vigo.greet # => "Hello Uğur"
  21. 35.

    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 }
  22. 36.

    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
  23. 37.

    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"