Created
April 7, 2011 19:11
-
-
Save goz/908467 to your computer and use it in GitHub Desktop.
basic ruby metaprogramming
This file contains 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 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