给出以下方法:
def some_method
:value
end
Run Code Online (Sandbox Code Playgroud)
以下语句按预期工作:
some_method || :other
# => :value
x = some_method || :other
# => :value
Run Code Online (Sandbox Code Playgroud)
但是以下陈述的行为让我感到困惑:
some_method = some_method || :other
# => :other
Run Code Online (Sandbox Code Playgroud)
它创建一个名为some_methodexpected 的局部变量,以及后续调用以some_method返回该局部变量的值.但为什么要分配:other而不是:value?
我知道这可能不是一件明智的事情,并且可以看出它是如何模棱两可的,但我认为应该在考虑任务之前对作业的右侧进行评估......
我已经在Ruby 1.8.7和Ruby 1.9.2中测试了这个,结果相同.
干杯!
保罗
想象一下std:vector,比如说,当前有100个东西(0到99).你将它视为一个循环.所以第105项是索引4; 指数98的前锋7是5.
您想删除索引位置P后的N个项目.
所以,删除索引50后的5个项目; 简单.
或者在索引99之后有5个项目:当您删除0五次或4到0时,注意到99处的位置将被删除.
最糟糕的是,索引97之后的5个项目 - 你必须处理这两种删除模式.
什么是优雅和坚实的方法?
这是我写的一个无聊的例程
-(void)knotRemovalHelper:(NSMutableArray*)original
after:(NSInteger)nn howManyToDelete:(NSInteger)desired
{
#define ORCO ((NSInteger)[original count])
static NSInteger kount, howManyUntilLoop, howManyExtraAferLoop;
if ( ... our array is NOT a loop ... )
// trivial, if messy...
{
for ( kount = 1; kount<=desired; ++kount )
{
if ( (nn+1) >= ORCO )
return;
[original removeObjectAtIndex:( nn+1 )];
}
return;
}
else // our array is a loop
// messy, confusing and inelegant. how to improve?
// here …Run Code Online (Sandbox Code Playgroud) 刚开始学习boost :: filesystem.
谢谢
下面的例子来自Jon Skeet的文章" 参数传递C# ".
我的问题是:为什么变量y 在第一个例子中不为 null,而我们在第二个例子中看到它已被更改:
1-
void Foo (StringBuilder x)
{
x = null;
}
...
StringBuilder y = new StringBuilder();
y.Append ("hello");
Foo (y);
Console.WriteLine (y==null);
Run Code Online (Sandbox Code Playgroud)
2-
void Foo (StringBuilder x)
{
x.Append (" world");
}
...
StringBuilder y = new StringBuilder();
y.Append ("hello");
Foo (y);
Console.WriteLine (y);
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试使用SCons编译一个程序,该程序需要一组依赖项,我已经安装在非标准位置.
我在/ home/dja/ocr中安装了依赖项.现在我正在尝试编译主程序,无法弄清楚如何告诉SCons在哪里查找库和头文件.
我试过(除其他外):
scons prefix=/home/dja/ocr
scons includepath=/home/dja/ocr/include libpath=/home/dja/ocr/lib
env LIBPATH=/home/dja/ocr/lib INCLUDEPATH=/home/dja/ocr/include scons
...etc...
Run Code Online (Sandbox Code Playgroud)
结果总是一样的:
scons: Reading SConscript files ...
Currently supported OS version: Ubuntu 10.04
Checking for C++ library iulib... no
AssertionError: :
File "/home/dja/ocr/src/ocropus/SConstruct", line 107:
assert conf.CheckLibWithHeader("iulib","iulib/iulib.h","C++");
Run Code Online (Sandbox Code Playgroud)
我无法在Google上找到答案.
什么是正确的SCons foo才能让它工作?
在SOA项目中使用Service Bus体系结构的优缺点是什么?
您建议使用哪些建议的开源服务总线平台?
提前致谢
在视图函数中,我有类似的东西:
try:
url = request.POST.get('u', '')
if len(url) == 0:
raise ValidationError('Empty URL')
except ValidationError, err:
print err
Run Code Online (Sandbox Code Playgroud)
输出是一个字符串: [u'Empty URL']
当我尝试将错误消息传递给我的模板(填入dict,类似的东西{ 'error_message': err.value })时,模板成功获取消息(使用{{ error_message }}).
问题是,我得到与上面完全相同的字符串[u'Empty URL'],用[u'...']!
我怎么摆脱它?
(Python 2.6.5,Django 1.2.4,Xubuntu 10.04)
我在symfony项目上使用Doctrine 1.2,我正在考虑在我的模式中混合具体和列聚合继承类型:列聚合让我在父表中查询并获取父记录和子记录,而具体的继承让我得到更清洁的架构.此外,混合将在同一个继承链中.我该如何编写模式文件?喜欢以下?
A:
B:
inheritance:
extends: A
type: concrete
C:
inheritance:
extends: B
type: column_aggregation
keyField: type
keyValue: 1
Run Code Online (Sandbox Code Playgroud)
或者这样或许:
A:
B:
inheritance:
extends: A
type: concrete
C:
inheritance:
extends: B
type: concrete
D:
inheritance:
extends: C
type: column_aggregation
keyField: type
keyValue: 1
E:
inheritance:
extends: C
type: column_aggregation
keyField: type
keyValue: 2
Run Code Online (Sandbox Code Playgroud)
有危险/警告吗?
inheritance doctrine symfony1 concrete-inheritance column-aggregation