第一行代码执行我想要的,第二行只是将第一个单词大写:
<%= the_label = "Time_Balance".titlecase %><br />
<%= f.label "Time_Balance".titlecase %><br />
Run Code Online (Sandbox Code Playgroud)
我想标记输入标签,但我无法管理它.
这也行不通:
<%= the_label = "Time_Balance".titlecase %><br />
<%= f.label the_label %><br />
Run Code Online (Sandbox Code Playgroud)
这也不是:
<%= the_label = "Time_Balance" %><br />
<%= f.label the_label.titlecase %><br />
Run Code Online (Sandbox Code Playgroud) 在另一页上看到这个:
"使用getter,可以获得@a的当前值,而无需修改它."
"使用setter,one修改@a,并将其新值作为返回值."
但是,从cancan wiki查看这段代码,我发现setter和getter实际上都在为它中的变量做些什么.
def roles=(roles)
self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.inject(0, :+)
end
def roles
ROLES.reject do |r|
((roles_mask || 0) & 2**ROLES.index(r)).zero?
end
end
Run Code Online (Sandbox Code Playgroud)
看起来getter实际上是返回一个真值,如果不是,那么至少是某种变换.那么这个"getters得到了没有修改,setter设置与修改"规则实际上是真的吗?
这是我的问题:
我有五列的文本文件.最后一个总是有一个数字.反斜杠在前三个是非法的.空格可能会显示在第一列中.我删除了第一列中最后一个@之后的所有内容.列由空格分隔.我可以将列宽设置为我想要的任何值,让我对列之间的间距进行一些控制.
所以,我可能有这样的事情:
D Smith Application Database Read 2
Run Code Online (Sandbox Code Playgroud)
我有代码将其转换为:
grant read on database 'Application'.'Database' to 'D Smith';
Run Code Online (Sandbox Code Playgroud)
这是我创建的正则表达式代码,用于分隔每个字段,避免混淆第一个字段中的任何空格与分隔间距.
while (<>) {
s/^ //m;
if (/^([^\\]+?)( {80,})/) {
my $atindex = rindex($1,"@",);
my $username = substr($1,0,$atindex);
if ($atindex != -1) {
s/^([^\\]+?)( {80,})/$username $2/m;
s/ {2,}/ \\ \\ /g;
s/\\ \d$//gm;
s/ \\ $//gm;
}
}
Run Code Online (Sandbox Code Playgroud)
这样做是\\ \\在字段之间做分隔符.然后我使用此代码进行转换:
if (/([^\\]+) \\ \\ ([^\\]+) \\ \\ ([^\\]+) \\ \\ ([^\\]+)\n/) {
if ($4 eq "any") {
my $execany = …Run Code Online (Sandbox Code Playgroud) 这是我的脚本:
use strict;
use warnings;
while (<>) {
/(@.*)/;
print $`;
}
Run Code Online (Sandbox Code Playgroud)
它执行正确 - 在匹配之前打印所有内容 - 但我明白了:
Use of uninitialized value $` in print at FindAdd.pl line 6, <> line 1.
Use of uninitialized value $` in print at FindAdd.pl line 6, <> line 2.
Use of uninitialized value $` in print at FindAdd.pl line 6, <> line 3.
Use of uninitialized value $` in print at FindAdd.pl line 6, <> line 4.
Run Code Online (Sandbox Code Playgroud)
当然,如果我不使用警告,我可以避免这种情况,但我想知道是否有更好的方法来避免警告.$`必须初始化吗?