我正在尝试测试以下方法:
def unprocess_move(board, move)
if move[0].instance_of?(Array)
multi_move = @multi_move.pop(2).reverse
multi_move.each do |single_move|
unapply_move(board, single_move)
end
else
board = unapply_move(board, move)
end
board
end
Run Code Online (Sandbox Code Playgroud)
我想为@multi_move设置状态,但我不想添加一个仅用于测试的访问器.没有访问器有没有办法这样做?谢谢.
我有这样的测试:
it "should not indicate backwards jumps if the checker position is not a king" do
board = Board.new
game_board = board.create_test_board
board.add_checker(game_board, :red, 3, 3)
x_coord = 3
y_coord = 3
jump_locations = {}
jump_locations["upper_left"] = true
jump_locations["upper_right"] = false
jump_locations["lower_left"] = false
jump_locations["lower_right"] = true
adjusted_jump_locations = @bs.adjust_jump_locations_if_not_king(game_board, x_coord, y_coord, jump_locations)
adjusted_jump_locations["upper_left"].should == true
adjusted_jump_locations["upper_right"].should == false
adjusted_jump_locations["lower_left"].should == false
adjusted_jump_locations["lower_right"].should == false
end
Run Code Online (Sandbox Code Playgroud)
我知道,这是冗长的.是否有更简洁的方式来陈述我的期望.我看过文档,但我看不出在哪里压缩我的期望.谢谢.
使用我的第一台Mac进行开发,我发现即使我-c在命令中使用了' '标志,我的Rspec输出也没有在我的终端中着色:bundle exec rspec -c -fd.有任何想法吗?
我想在"Away Team"和"Baseball Field"div之间加一个小的水平空间,如这个小提琴:http://jsfiddle.net/VmejS/.我试过改变填充,边距,包括十进制列偏移,都没有成功.
这是html:
<body>
<div class='container'>
<div class='row'>
<div class='col-md-12 panel' id='gameplay-title'>Title</div>
</div>
<div class='row'>
<div class='col-md-6 col-md-offset-3 panel' id='gameplay-scoreboard'>Scoreboard</div>
</div>
<div class='row'>
<div class='col-md-3 panel' id='gameplay-away-team'>Away Team</div>
<div class='col-md-6 panel' id='gameplay-baseball-field'>Baseball Field</div>
<div class='col-md-3 panel' id='gameplay-home-team'>Home Team</div>
</div>
<div class='row'>
<div class='col-md-6 col-md-offset-3 panel' id='gameplay-at-bat'>At Bat</div>
</div>
<div class='row'>
<div class='col-md-6 col-md-offset-3 panel' id='gameplay-game-report'>Game Report</div>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud) 我有一个包含这个类方法的类:
def self.get_event_record(row, participant)
event = Event.where(
:participant_id => participant.id,
:event_type_code => row[:event_type],
:event_start_date => self.format_date(row[:event_start_date])
).first
event = Event.new(
:participant_id => participant.id,
:event_type_code => row[:event_type],
:event_start_date => self.format_date(row[:event_start_date])
) if event.blank?
event
end
Run Code Online (Sandbox Code Playgroud)
我在同一个类中也有一个实例方法:
def format_date(date)
parsed_date = date.split('/')
# if month or day are single digit, make them double digit with a leading zero
if parsed_date[0].split("").size == 1
parsed_date[0].insert(0, '0')
end
if parsed_date[1].split("").size == 1
parsed_date[1].insert(0, '0')
end
parsed_date[2].insert(0, '20')
formatted_date = parsed_date.rotate(-1).join("-")
formatted_date
end
Run Code Online (Sandbox Code Playgroud)
我得到一个'未定义的方法'错误#format_date.( …
测量工作代码(在一个名为Surveyor的模块中,不能少),试图理解它.我跑过这个包含模块中的类的部分.这和包含模块一样吗?如果没有,这样做有什么好处?谢谢.(奖励要点:为什么我们将自己附加到课堂上,是不是已经隐含了?)
module Surveyor
class Common
RAND_CHARS = [('a'..'z'), ('A'..'Z'), (0..9)].map{|r| r.to_a}.flatten.join
OPERATORS = %w(== != < > <= >= =~)
class << self
def make_tiny_code(len = 10)
if RUBY_VERSION < "1.8.7"
(1..len).to_a.map{|i| RAND_CHARS[rand(RAND_CHARS.size), 1] }.join
else
len.times.map{|i| RAND_CHARS[rand(RAND_CHARS.size), 1] }.join
end
end
def to_normalized_string(text)
words_to_omit = %w(a be but has have in is it of on or the to when)
col_text = text.to_s.gsub(/(<[^>]*>)|\n|\t/su, ' ') # Remove html tags
col_text.downcase! # Remove capitalization
col_text.gsub!(/\"|\'/u, '') # Remove potential problem characters …Run Code Online (Sandbox Code Playgroud) 我不确定为什么,但我的Bash别名似乎不起作用.这是我的.bashrc档案
# v 0.0.1 - 7/03/12
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
# expanding history to 10000 commands
export HISTSIZE=10000
# don't store repeated commands more than once
export HISCONTROL=ignoredups
# where to look for Java
export JAVA_HOME=/Library/Java/Home
# tomcat server configuration
export CATALINA_HOME=/usr/local/apache-tomcat-6.0.35
# default editor
export EDITOR=vim
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Run Code Online (Sandbox Code Playgroud)
这是我的 …
背景:我正在做的工作的一部分涉及将文字段落从单词doc粘贴到ruby文件中.
问题:这些段落被粘贴为一个非常长的文本行,我必须手动插入换行符以使行条合理.
解决方案:有没有办法让粘贴函数"意识到"合理的边距限制并在粘贴时将文本换行?
我有一个方法:
def deltas_to_board_locations(deltas, x, y)
board_coords = []
deltas.each_slice(2) do |slice|
board_coords << x + slice[0]
board_coords << y + slice[1]
end
board_coords
end
Run Code Online (Sandbox Code Playgroud)
其中deltas是一个数组,x,y是fixnums.
有没有办法消除第一行和最后一行,使方法更优雅?
喜欢:
def deltas_to_board_locations(deltas, x, y)
deltas.each_slice(2) do |slice|
board_coords << x + slice[0]
board_coords << y + slice[1]
end
end
Run Code Online (Sandbox Code Playgroud) 所以这起作用越来越强
(1..5).to_a => [1, 2, 3, 4, 5]
Run Code Online (Sandbox Code Playgroud)
但事实并非如此
(5..1).to_a => []
Run Code Online (Sandbox Code Playgroud)
我试图从任意上限得到一个降序.谢谢.