十年之前
Ruby on Rails 另一個讓我感到很驚訝的部份
就是他製作 lib 的想法,完全遵照 The Ruby Way
那你程式就越好維護
不了解我的意思嗎?
給個小範例
if Time.now - session[:last_login_time] > 3600
上面這段代表什麼意思,如果上次 login 的時間距離現在的時間只要超過 3600 秒(也就是一小時)就成立
我們可以改成
if Time.now - session[:last_login_time] > 3600.seconds
上面這段什麼意思,跟上面一模一樣
我們還可以改成
if Time.now - session[:last_login_time] > 1.hours
上面這段什麼意思,跟上面一模一樣
最後最後我們還可以改成
Session[:last_login_time] < 1.hours.ago
所以陳奕迅的歌可以改成 10.years.ago
當然還有 1.hours + 2.days 這樣的搞法@@!
本 lib 是 Rails 裡面的 ActiveSupport::CoreExtensions::Numeric::Time
要在Ruby 裡面使用請先宣告
require 'active_support'
然後就可以使用啦
當然啦,沒有 metaprogramming 觀念的語言是搞不出這種玩意的:p
就是他製作 lib 的想法,完全遵照 The Ruby Way
一切以為人為本當你的程式越接近人的語言
那你程式就越好維護
不了解我的意思嗎?
給個小範例
if Time.now - session[:last_login_time] > 3600
上面這段代表什麼意思,如果上次 login 的時間距離現在的時間只要超過 3600 秒(也就是一小時)就成立
我們可以改成
if Time.now - session[:last_login_time] > 3600.seconds
上面這段什麼意思,跟上面一模一樣
我們還可以改成
if Time.now - session[:last_login_time] > 1.hours
上面這段什麼意思,跟上面一模一樣
最後最後我們還可以改成
Session[:last_login_time] < 1.hours.ago
所以陳奕迅的歌可以改成 10.years.ago
當然還有 1.hours + 2.days 這樣的搞法@@!
本 lib 是 Rails 裡面的 ActiveSupport::CoreExtensions::Numeric::Time
要在Ruby 裡面使用請先宣告
require 'active_support'
然後就可以使用啦
當然啦,沒有 metaprogramming 觀念的語言是搞不出這種玩意的:p
1 則留言:
I have intended to play for a long time to turn a roulette in an online casino, but I can not make a choice as for a proper inspiring trust gamble-resource.
With varying success I played tested my fortune on conditional money in such internet casinos, as Grand Casino, Vabank, in JOKERBANK, in AceKing.
As a matter of fact, while you are playing on conditional money virtual stakes you win often enough. There is a question – whether I can entrust casino real money.
I have heard that there are some diplomas certificates which special commissions on supervising internet gambling give to casinos.
I am curious I wonder - where it is possible to look at them and what their form is in general.
Also I have seen in some casinos an option trick - «honesty control» - there are some figures and letters in the window, I can not understand what it can mean how much I can trust it.
Then, if to transfer won money on electronic wallet - who will pay the commission to Webmoney system?
And, at last, the main thing is why do we need bonuses if they are necessary to be won back in a real form, which exceeds the bonus sum by 20-30 times? That is, to receive $1 from the casino I am charged I should risk $30? Can it be profitable?
I am thankful in advance I will be grateful for any advice and answers to the above-mentioned questions.
[url=http://blackjackcasinoblog.com]Casino Blog[/url]
張貼留言