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
require 'minitest/autorun' | |
require './flatten' | |
describe 'Flatten' do | |
it 'invalid parameter' do | |
assert_raises(ArgumentError) do | |
ArrayUtils.flatten(1) | |
end | |
end | |
it 'empty array' do |
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
module ArrayUtils | |
def self.flatten(a, ret = []) | |
raise ArgumentError, 'parameter must be an array' unless a.is_a?(Array) | |
a.each do |i| | |
if i.is_a?(Array) | |
flatten(i, ret) | |
else | |
ret << i | |
end | |
end |
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
#!/bin/bash | |
echo Installing dependencies... | |
# APT based systems. Tested on: Ubuntu 14.04 | |
[[ -f /etc/debian_version ]] && sudo apt-get update | |
[[ -f /etc/debian_version ]] && sudo apt-get -y install git mercurial curl build-essential libzip-dev | |
# RPM based systems. Tested on: CentOS 7 | |
[[ -f /etc/redhat-release ]] && [[ -x /usr/bin/sudo ]] || yum -y install sudo | |
[[ -f /etc/redhat-release ]] && sudo yum -y groupinstall "Development Tools" --exclude=subversion --exclude='systemtap*' --exclude=valgrind |
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
def rails_between(min, max) | |
Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new(min) && Gem::Version.new(Rails::VERSION::STRING) <= Gem::Version.new(max) | |
end | |
if rails_between('3.0.0', '3.0.18') || rails_between('3.1.0', '3.1.9') || rails_between('3.2.0', '3.2.10') | |
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML) | |
end | |
if rails_between('2.0.0', '2.3.14') | |
ActionController::Base.param_parsers.delete(Mime::XML) | |
end |