This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Params < Hash | |
| def initialize(qs) | |
| parse_query_string!(qs) | |
| end | |
| def parse_query_string!(qs) | |
| pairs = qs.split('&') | |
| pairs.each do |pair| | |
| key, value = *pair.split('=') | |
| self[key] = value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # the hash | |
| hash = Hash.new {|h,k| h[k] = 0} | |
| # populate the hash | |
| File.open('email').each do |line| | |
| line.split(/\s+/).each do |word| | |
| hash[word] += 1 | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LuckyArray < Array | |
| def self.from_string(str) | |
| new str.split('').map(&:to_i) | |
| end | |
| def front_half | |
| slice 0, length/2 | |
| end | |
| def back_half |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def triangle(a, b, c) | |
| Triangle.new(a, b, c).type | |
| end | |
| class Triangle | |
| def initialize(a, b, c) | |
| @sides = *a, b, c | |
| end | |
| attr_reader :sides |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def triangle(a, b, c) | |
| sides = *a, b, c | |
| if sides.uniq.length == 1 | |
| :equilateral | |
| elsif sides.uniq.length == 2 | |
| :isosceles | |
| else | |
| :scalene | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| text = (1..10_000).inject('') do |str, num| | |
| str << "#{num} ".gsub(/0/,' ') | |
| end | |
| total = text.split(' ').map(&:to_i).inject(:+) | |
| puts total |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| remove Lock = Caps_Lock | |
| keysym Caps_Lock = Control_L | |
| add Control = Control_L | |
| keycode 107 = Menu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('#audio').on 'pause', -> | |
| $('#to') | |
| .val @currentTime.toFixed(2) | |
| .trigger 'update' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Object | |
| def isnt?(*args) | |
| arr = args.first.is_a?(Array) ? args.first : args | |
| !arr.include? self | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Numeric | |
| def percent | |
| self.to_f / 100 | |
| end | |
| end |
OlderNewer