Upload
stefan-kanev
View
1.057
Download
5
Embed Size (px)
DESCRIPTION
Нулева лекция от курса по Ruby и Rails.
Citation preview
0. За курса, Ruby и Railst
Textclass RubyAndRails < Course speaker "Стефан Кънев" speaker "Николай Бачийски"end
06.10.2008, ФМИ
3
3Събирания във ФМИ
3Събирания във ФМИ
Събирания навън
3Събирания във ФМИ
Събирания навън
Сайт на курса
∀ понеделник и сряда
∀ понеделник и сряда
19:00 - 21:00
∀ понеделник и сряда
19:00 - 21:00
зала 200
http://fmi.rails-bg.net/
•Домашни•Споделяне на код•Въпроси и отговори•Информация за курса
Догматичност(Не очаквахте испанската инквизиция, а?)
Оценки
200+• Отговори във форума
• Елегантни решения
• Втори проект през семестъра
• Допълнителни задачи
Ruby
Ruby Ruby
RubyRubyRuby
RubyRubyRuby
Ruby Ruby
RubyRubyRuby
RubyRubyRuby Web
Ruby Ruby
RubyRubyRuby
RubyRuby
HTTP
SQL
(X)HTML
CSSRuby Web
Ruby Ruby
RubyRubyRuby
RubyRuby
HTTP
SQL
(X)HTML
CSSRuby Web
Rails
Ruby Ruby
RubyRubyRuby
RubyRuby
HTTP
SQL
(X)HTML
CSS
Rails
Rails
RailsRails
RailsRails
Rails
Rails
Ruby Web
Rails
Ruby Ruby
RubyRubyRuby
RubyRuby
HTTP
SQL
(X)HTML
CSS
Rails
Rails
RailsRails
RailsRails
Rails
Rails
Ruby Web
Rails
Ruby
Ruby
Ruby
Ruby Ruby
RubyRubyRuby
RubyRuby
HTTP
SQL
(X)HTML
CSS
Rails
Rails
RailsRails
RailsRails
Rails
Rails
Ruby Web
Rails
JavaScript
Ruby
Ruby
Ruby
Ruby Ruby
RubyRubyRuby
RubyRuby
HTTP
SQL
(X)HTML
CSS
Rails
Rails
RailsRails
RailsRails
Rails
Rails
AJAX
JSON
Ruby Web
Rails
JavaScript
Ruby
Ruby
Ruby
Ruby Ruby
RubyRubyRuby
RubyRuby
HTTP
SQL
(X)HTML
CSS
Rails
Rails
RailsRails
RailsRails
Rails
Rails
AJAX
JSON
?
Ruby Web
Rails
JavaScript
Ruby
Ruby
Ruby
1995
Интерпретира се
aquarius@arrakis:~$ cat sample.rb require 'date'puts "Hello world"puts "The exact time is #{DateTime.now}"aquarius@arrakis:~$ ruby sample.rb Hello worldThe exact time is 2008-10-05T14:40:14+03:00
aquarius@arrakis:~$ irb 001:0> names = ["Stefan", "Nikolay"]=> ["Stefan", "Nikolay"]002:0> surnames = ["Kanev", "Bachiyski"]=> ["Kanev", "Bachiyski"]003:0> names.zip(surnames).map { |f,l| "#{f} #{l}" }=> ["Stefan Kanev", "Nikolay Bachiyski"]
Интерактивен шел (IRB)
Динамичен
ООП
ФП
+ =
Smalltalk
LISP
CLU
essay pic SICP
Programs must be written for people to read, and only
incidentally for machines to execute
Matz(Yukihiro Matsumoto, 松本行)
• Benevolent Dictator For Life• 43 годишен• Спокоен, приятен човек• Мормон
Интерпретатори
•MRI (Matz's Ruby Interpreter)• YARV (Yet Another Ruby VM)• Rubinus (вдъхновен от Smalltalk)• JRuby (сещате се)• IronRuby
Платформа
2004-
MVC
Text
class User < ActiveRecord::Base validates_presence_of :email, :name, :birthday, :gender, :city validates_uniqueness_of :email, :case_sensitivity => false belongs_to :city has_many :comments, :dependent => :destroy has_many :received, :class_name => 'Message', :foreign_key => 'recipient_id' def self.authenticate(email, password) u = find_by_email(email) u && u.authenticated?(password) ? u : nil
Active Record
<% ERB %>
Controller
Controller
TDD
Migrations
Plugins
github
DHH(David Heinemeier Hanson)
• Създател на Rails• 28 годишен • Нахакан, арогантен тип• Дътчанин
I’m not here to create Rails for you. I’m here to create Rails for me and if you happen to like that version of Rails that I’m creating for
me, than you are going to have a great time
category_sum = Hash.new(0)
File.open('spendings').each_line do |line| next unless line =~ /^\d\d\.\d\d\.\d{4}\s+\w+\s+[-0-9.]+/ date, category, amount = line.split category_sum[category] += amount.to_iend
category_sum.sort_by { |_, sum| -sum }.each do |category, sum| puts "#{sum} spent on #{category}"end
04.10.2008 lolcat 1004.10.2008 lolcat 1
05.10.2008 iMac 2375# I am getting compulsive05.10.2008 lolcat 20
06.10.2008 bet -20# Clayderman!!! 06.10.2008 tickets 60
# Let's never play poker again07.10.2008 bet 100
nb@creep$ ruby iamfrugal.rb 2375 spent on iMac80 spent on bet60 spent on tickets31 spent on lolcat
Text
def symmetric? points = Set.new @bricks.map(&:points).sum left, right, top, bottom = WIDTH * 2, -WIDTH * 2, HEIGHT * 2, -HEIGHT * 2 points.each do |x, y| left = [left, x].min right = [right, x].max top = [top, y].min bottom = [bottom, y].max end points.all? { |x, y| points.include? [right - x + left, y] } or \ points.all? { |x, y| points.include? [right - x + left, bottom - y + top] } end
Text
def try board, bricks if bricks.empty? board.print_me if ($c % 10000).zero? $c +=1 if board.symmetric? puts 'symmetric! '*100 p board board.print_me end #gets if board.symmetric? #board.print_me #puts "-" * 30 return end bricks = bricks.dup brick = bricks.pop brick.rotate do |rotation| board.put rotation do try board, bricks end endend
Ruby няма да ви нареди магнитите, но ще ви даде няколко безценни часа
забавление