Class methods are methods added on the singleton class of the object.
class Mail
def self.is_delivered?
true
end
self.singleton_class.send(:alias_method, :delivered?, :is_delivered?)
end| Time.now.strftime("%F %T") # => shortcut to strftime('%Y-%m-%d HH:MM:SS') |
| cell_42 = ['inmate #42', 'inmate #43'] | |
| common_room = ['inmate #40', 'inmate #41', *cell_42, 'inmate #44'] | |
| # => ['inmate #40', 'inmate #41', 'inmate #42', 'inmate #43', 'inmate #44'] |
| # Use this pattern instead of a long case when: | |
| # case cocktail | |
| # when 'mojito' | |
| # ["lemon", "mint", "rhum"] | |
| # ... | |
| # when 'lemon coke' | |
| # ["coke", "lemon"] | |
| # end |
Class methods are methods added on the singleton class of the object.
class Mail
def self.is_delivered?
true
end
self.singleton_class.send(:alias_method, :delivered?, :is_delivered?)
end| # AR Scoping permit to dinamically build you query in multiple steps | |
| # Initialize an 'empty' scope | |
| scope = Pokemon.where(nil) | |
| scope = scope.select(:id) | |
| scope = scope.where(created_at: (Time.now - 1.month)..(Time.now)) | |
| scope = scope.limit(5) |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta name="description" content="react - state"> | |
| <script src="http://fb.me/react-0.13.1.js"></script> | |
| <meta charset="utf-8"> | |
| <title>JS Bin</title> | |
| <style id="jsbin-css"> | |
| #spacer{ | |
| margin: 100px 0 20px 0; |
| 8.to_s(2) # => "00001000" | |
| 6.to_s(2) # => "00000110" | |
| 2.to_s(2) # => "00000010" | |
| 1.to_s(2) # => "00000001" | |
| (2 & 1).to_s(2) # => "00000000" because it applies an AND operation on each bit. (1 & 1) match | |
| (2 | 1).to_s(2) # => "00000011" because it applies an OR operation on each bit. (1 | 1), (1 | 0), (0 | 1) match ! | |
| (6 ^ 2).to_s(2) # => "00000100" because it applies a XOR operation on each bit. (1 | 0), (0 | 1) match ! | |
| (8 >> 2).to_s(2) # => "00000010" right-shift operator. Each bit is shifted 2 bits to the right. | |
| (2 << 2).to_s(2) # => "00001000" left-shift operator. Each bit is shifted 2 bits to the left. |
###Prerequisites
?> gem install wcr###Then
?> wcr -l `ls | grep -v -E "LICENSE|Gemfile\.lock"` # chain files that you want to omit.