Skip to content

Instantly share code, notes, and snippets.

@goz
Created April 7, 2011 19:11
Show Gist options
  • Save goz/908467 to your computer and use it in GitHub Desktop.
Save goz/908467 to your computer and use it in GitHub Desktop.
basic ruby metaprogramming
class Array
def remove(*args)
string_params = ""
args.each do |arg_item|
string_params += arg_item
end
flatten.collect { |k| k.delete string_params}
end
def repeat(int)
initial_array = collect { |j| j.to_s.split * int}
initial_array.flatten
end
end
require 'meta-test.rb'
true
["one", "two", "three"].repeat(2)
["one", "one", "one", "two", "two" "three", "three"]
%w{one two three four five six}.remove("i","o")
["ne", "tw", "three", "fur", "fve", "sx"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment