ActiveSupport::Callbacks
延續上一篇,這邊用 ActiveSupport::Callbacks 來做 callbacks 官方教學: http://api.rubyonrails.org/classes/ActiveSupport/Callbacks.html 下一個問題: 所以怎麼做到下...
rails singleton class
```rb # File activesupport/lib/active_support/core_ext/object/singleton_class.rb, line 3 def singleton_class class << self ...
bitcoin address validation
第一時間會想到用正規表示來驗證 正式 chain 的 regex ``` \A[13][a-km-zA-HJ-NP-Z1-9]{25,34}\z ``` Test net 的 regex ``` \A[2mn][1-9A-HJ-NP-Za-km-z]{26,35}\...
怎麼在 rake task 裡面跑 task
最簡單: ```ruby task build: [ "migration:t15349:create_init_version_for_all_accounts", "migration:t15349:migrate_account_version", "migrati...
Metaprograming 做 after method callback
Magic ```ruby class Example def self.after(*names) names.each do |name| m = instance_method(name.to_s) # override ol...
Ruby exceptions 進階
backtrace `error.backtrace` 可以看出是在哪裡報錯 如果 rescue 後再 raise 還可以看出是上一個 error 是什麼 ```rb def fail_and_reraise raise NoMethodError res...
Ruby 可以在 class 內定義 exception method,這樣就可以 raise 這個 class
不囉唆,上 code Raising Non-Exceptions If we provide an exception method, any object can be raised as an exception. Imagine you have a cla...
非常詳細且很棒的 hypermedia api 介紹
讓 client side 知道下一步做什麼,進而可以寫出像 call method 一樣的 client helper。 https://robots.thoughtbot.com/writing-a-hypermedia-api-client-in-ruby