On Github jlucasps / seti-ufla-2014
Semana de Tecnologia da Informação - SETI UFLA João Lucas P Santana - @jlucasps
Java Developer
Ruby/Rails Developer
JavaScript Developer
Feb. 23 1993
"... object-oriented scripting language. I knew Perl (Perl4, not Perl5), but I didn't like it really, because it had smell of toy language (it still has)."
"I knew Python then. But I didn't like it, because I didn't think it was a true object-oriented language."
"So, I decided to make it." Matz
"It took several months to make the interpreter run. [...] I posted Ruby 0.95 to the Japanese domestic newsgroups in Dec. 1995. " Matz
4.even? # => true 3.upto(8).to_a # => [3, 4, 5, 6, 7, 8] "A string literal".length() # => 16
[].methods => [:inspect, :to_s, :to_a, :to_ary, :frozen?, :==, :eql?, :hash, :[], :[]=, :at, :fetch, :first, :last, :concat, :<<, :push, :pop, :shift, :unshift, :insert, :each, :each_index, :reverse_each, :length, :size, :empty?, :find_index, .... ]
10.methods => [:to_s, :inspect, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===, :<=>, :>, :>=, :<, :<=, :~, :&, :|, :^, :[], :<<, :>>, :to_f, :size, :zero?, :odd?, :even?, :succ, :integer?, :upto, :downto, :times, :next, :pred, :chr, :ord, :to_i, :to_int, :floor, :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, :singleton_method_added, :coerce, :i, :+@, :eql?, ... ]
true.class => TrueClass 1.4.class => Float
'1+3i'.to_c.class => Complex '1+3i'.to_c.class.ancestors => [Complex, Numeric, Comparable, Object, Kernel, BasicObject]
'1+3i'.to_c.class.class => Class
class InfoCompMagazine # ... endMétodos e variáveis usam snake_case
def number_of_pages # some code here ... end def web_magazine? # more code ... end def change_folder! # code code code ... end
class Book def initialize(title) @title = title end def title @title end end
book = Book.new "Eloquent Ruby" puts book.title # "Eloquent Ruby" puts book.send :title # "Eloquent Ruby"
book = Book.new( "Eloquent Ruby" ) puts book.title() # "Eloquent Ruby" puts book.send( :title ) # "Eloquent Ruby"
// Java class public class Person { private int age; public int getAge() { return this.age } public void setAge(int age) { this.age = age; } }
# Ruby class class Person attr_accessor :age end
class Magazine MAX_PAGES = 30 # contants end
class Magazine def initialize @max_pages = 30 # instance variable end end
class Magazine @@max_pages = 30 # class variable def initialize # ... end end
class Fixnum def +( num ) self - num end end puts 2 + 3
=> -1
Armando Fox, University of California, Berkeley
def print_user_info( info ) puts "Info about user:" info.each_pair { |key, value| puts "#{key}: #{value}" } end print_user_info( { name: "Joao lucas", email: "jlucasps@gmail.com" } ) # Info about user: # name: Joao lucas # email: jlucasps@gmail.com
print_user_info( name: "Joao lucas", email: "jlucasps@gmail.com" ) print_user_info name: "Joao lucas", email: "jlucasps@gmail.com"
Armando Fox, University of California, Berkeley
user.age.should(be() >= 18) user.age.should be >= 18
if !logged_in?() # unless logged_in?() ( redirect_to( login_page() ) ) and return() end # ... ( redirect_to( login_page() ) and return() ) unless logged_in?() # ... ( redirect_to login_page and return ) unless logged_in?
class Car end car = Car.new car.run # undefined method `run' for #<Car:0x00000001c8d970> (NoMethodError)
# singleton method def car.run puts "wooowww Car running now!" end car.run # wooowww Car running now!
car2 = Car.new car2.run # undefined method `run' for #<Car:0x00000002292898> (NoMethodError)
class User attr_accessor :name, :age, :city def initialize name, age, city @name, @age, @city = name, age, city end end user = User.new "João Lucas", 25, "BH" puts "#{user.name}, #{user.age()} years old, from #{user.city}." puts user.move( "BH", "POA" )
# Joao Lucas, 25 years old, from BH. # undefined method `move' for #<User:0x994cee8 @name="João Lucas", @age=25, @city="BH"> (NoMethodError)
class User def method_missing( method, *args, &block) puts "ops.. you can not call #{method}(..) with params #{args.to_a} right now." puts "Try again next week! :-D" end end puts user.move( "BH", "POA" )
# Joao Lucas, 25 years old, from BH. # ops.. you can not call move(..) with params ["BH", "POA"] right now. # Try again next week! :-D
class User MOVE_OPTIONS = [:trip, :travel, :move, :go] MOVE_OPTIONS.each do | name | define_method( name ) do | *args | puts "Method #{name}(..) called with args #{args.inspect}" end end end puts user.move( "BH", "POA" )
# Method move(..) called with args ["BH", "POA"]
github.com/markets/awesome-rubygithub.com/bayandin/awesome-awesomeness
quora.com/What-are-some-highly-trafficked-sites-built-in-Ruby-on-Rails
Semana de Tecnologia da Informação - SETI UFLA João Lucas P Santana - @jlucasps