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 self.included(base) | |
| base.extend(ClassMethods) | |
| 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
| # Returns a hash of methods organized by their owner and method type. | |
| module Kernel | |
| def methods_by_owner | |
| output = {} | |
| output[:private_methods] = {} | |
| output[:instance_methods] = {} | |
| output[:protected_methods] = {} |
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
| require "yajl" | |
| parser = Yajl::Parser.new | |
| encoder = Yajl::Encoder.new | |
| regex = /(.*)asdf(\w+)\s+{3}/ | |
| regex_json = encoder.encode(regex) | |
| r = Regexp.new(parser.parse(regex_json)) | |
| => /(?-mix:.*asdf\w+\s+{3})/ | |
| "fooasdfblah argasdfbuh wowasdfderp" =~ r |
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
| # Strip leading zeroes, check if input matches after conversion to integer | |
| class String | |
| def is_num? | |
| self.to_i.to_s == self.gsub(/^0+/, '') | |
| end | |
| end | |
| > "045".is_num? | |
| => true |
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 A | |
| def some_instance_method | |
| "hi" | |
| end | |
| module ClassMethods | |
| def foo | |
| "asdf" | |
| 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 Test | |
| def initialize | |
| @atts = Hash.new | |
| end | |
| def prop=(value) | |
| @atts[:prop] = value | |
| end | |
| def prop |
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
| if days_to_wait == 1 | |
| puts "." | |
| else | |
| puts "s." | |
| 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 NotExecutable < RuntimeError; end | |
| begin | |
| f = File.open("test") | |
| raise NotExecutable unless File.executable?(f) | |
| rescue Errno::ENOENT => e | |
| puts e.inspect | |
| %x{touch test} | |
| retry | |
| rescue NotExecutable => e | |
| %x{chmod +x test} |
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
| params = {} | |
| security_group = {} | |
| opt_parser = OptionParser.new do |opts| | |
| opts.on("-c", "=CLASS", "") {|val| classes.push(val)} | |
| opts.on("-p", /[a-zA-Z0-9_-]+=.*/,"=PARAMETER=VALUE", | |
| "Set puppet variable PARAMETER to VALUE") do |val| | |
| a = val.split('=',2) | |
| params[a[0]] = a[1] | |
| 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
| config = {} | |
| config[:security_groups] = ["default"] | |
| config[:puppet_params] = {} | |
| opt_parser = OptionParser.new do |opts| | |
| opts.on("-c", "=CLASS", "") {|val| classes.push(val)} | |
| opts.on("-p", /[a-zA-Z0-9_-]+=.*/,"=PARAMETER=VALUE", | |
| "Set puppet variable PARAMETER to VALUE") do |val| |
OlderNewer