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
# Order one Array by the order of another Array in Ruby. | |
expected = [:john, :moishe, :bartholemew] | |
received = [:moishe, :bartholemew, :john] | |
sorted = received.sort_by {|name| expected.index(name)} | |
# => [:john, :moishe, :bartholemew] | |
# It should even handle shorter lists. | |
sorted = [:bartholemew, :john].sort_by{|name| expected.index(name)} |
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
module SetNotationHelper | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
# Here's our little magic hook | |
def inherited(subclass) | |
subclass.class_eval do |
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 YourKillerModel | |
# This method checks permissions for the :index action | |
def self.is_indexable_by(user, parent = nil) | |
end | |
# This method checks permissions for the :create and :new action | |
def self.is_creatable_by(user, parent = nil) | |
end | |
# This method checks permissions for the :show action | |
def is_readable_by(user, parent = nil) | |
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 Jovial | |
def self.laugh | |
puts "ha." | |
end | |
end | |
Affable = Jovial | |
Affable.laugh | |
# => ha. |
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 Sndfile | |
begin | |
helper = File.join(root, 'win32', 'sndfile-info.exe') | |
`#{helper} --version` | |
rescue Exception => e | |
puts e.inspect | |
begin | |
helper = File.join(root, 'osx', 'sndfile-info') | |
`#{helper} --version` |
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 Soundfile | |
# Windows | |
def info | |
`./bin/sndfile-info.exe` | |
end | |
# *nix | |
def info | |
`./bin/sndfile-info` |
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 Soundfile | |
if windows? | |
def info | |
... | |
end | |
else | |
def info | |
... | |
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 Soundfile | |
attr_accessor :info_bin | |
def initialize | |
@info_bin = (windows?) ? 'sndfile-info.exe' : 'sndfile-info' | |
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 SoundFile | |
attr_reader :binaries | |
delegate :info, :to => :binaries | |
def initialize | |
@binaries = Binaries.instance | |
end | |
end | |
module Binaries |
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
module DickCheney | |
def self.speak | |
puts "meeeh..." | |
end | |
end | |
DickCheney.speak | |
# => meeeh... | |
OlderNewer