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

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.

Uğur Özyılmazel

January 17, 2015
Tweet

More Decks by Uğur Özyılmazel

Other Decks in Programming

Transcript

  1. ş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
  2. 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
  3. 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__]
  4. class Fixnum def kere(n) self * n end end 5.kere(5)

    # => 25 5.kere(5).kere(2) # => 50
  5. 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
  6. 5.times do |i| puts "Ruby’i seviyorum, i = #{i}" if

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

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

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

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

    {:foo=>"bar"} # Eski {foo: "bar"} # => {:foo=>"bar"} # Yeni
  11. ÜNLEM İŞARETİ isim = "vigo" isim.reverse # => "ogiv" isim

    # => "vigo" isim.reverse! # => "ogiv" isim # => "ogiv"
  12. İ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
  13. İ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]
  14. class class Person attr_accessor :age end vigo = Person.new vigo

    # => #<Person:0x007f98820e6ab0> vigo.age = 43 vigo # => #<Person:0x007f98820e6ab0 @age=43> vigo.age # => 43
  15. 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"
  16. 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 }
  17. 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
  18. 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"