是否有更合适的方法来使一个子字符串比这个更简单?:
string[a..b] = string[a..b].downcase
也许是这样的:
string[a..b].downcase!
例如:
string = "RubyChangedMyMind"
string[1..string.length] = string[1..string.length].downcase
# this is working but i want to know if there is more short way to do this
# (indeces may be different)
# something like string[a..b].downcase!
答案 0 :(得分:0)
你可以制作proc:
~/.gitconfig
并随时调用它:
[alias]
mergeRepo = "!mergeRepo() { \
[ $# -ne 3 ] && echo \"Three parameters required, <remote URI> <new branch> <new dir>\" && exit 1; \
git remote add newRepo $1; \
git fetch newRepo; \
git branch \"$2\" newRepo/master; \
git checkout \"$2\"; \
mkdir -vp \"${GIT_PREFIX}$3\"; \
git ls-tree -z --name-only HEAD | xargs -0 -I {} git mv {} \"${GIT_PREFIX}$3\"/; \
git commit -m \"Moved files to '${GIT_PREFIX}$3'\"; \
git checkout master; git merge --allow-unrelated-histories --no-edit -s recursive -X no-renames \"$2\"; \
git branch -D \"$2\"; git remote remove newRepo; \
}; \
mergeRepo"
例如:
my_downcase = Proc.new { |str,n,m| str.chars.each_with_index.map{ |c,index| (n..m).include?(index) ? c.downcase : c }.join}