在 Ruby 中表达此语句的正确方式是什么?
我对此很陌生,并且很难找到用 Ruby 表达此内容的正确方法。而且我不知道SketchUp中的Ruby API是否有所不同。但是,这就是我想用它的目的。
def self.initialize_job_info
return{
'salesperson' => ' = $pg_settings['salespersons'[['salesperson']['id']]] if ('on' = $pg_settings['salespersons'[['salesperson']['defsales']]])'
这就是我基本上想做的:
这部分代码按其应有的方式工作
def self.initialize_job_info
return{
'salesperson' => ''
如果没有找到预先存在的值,它会将空表单的 job_info['salesperson'] 值的初始值设置为“ ”。
因此,我想在从 $pg_settings 传递的哈希中放置一个值。
我想要的值是,并且我希望这是有意义的,这个特定“id”的值
$pg_settings['salespersons'] {//which is a list of 'salesperson'
<salesperson> id="561" name="name" phone="phone number" defsales="on" email="email" </salesperson>
if (defsales == "on") then 'salesperson' => 'value="id"'
这有意义吗?
我正在拉扯我的头发,所以你能在这方面提供的任何帮助都会很棒。
I'm new at this, and I'm having trouble finding the proper way to phrase this in Ruby. And I don't know if the Ruby API in SketchUp is different. But, thats what I'm trying to use it for.
def self.initialize_job_info
return{
'salesperson' => ' = $pg_settings['salespersons'[['salesperson']['id']]] if ('on' = $pg_settings['salespersons'[['salesperson']['defsales']]])'
This is what I'm basically trying to do:
This part of the code works as it should
def self.initialize_job_info
return{
'salesperson' => ''
It sets an empty form's initial value of job_info['salesperson']'s value to ' ' if no pre-existing value is found.
So, there is a value I want to place in the Hash that is being passed from $pg_settings.
The value I want is, and I hope this make sense, the value of this specific 'id'
$pg_settings['salespersons'] {//which is a list of 'salesperson'
<salesperson> id="561" name="name" phone="phone number" defsales="on" email="email" </salesperson>
if (defsales == "on") then 'salesperson' => 'value="id"'
Does this make sense?
I'm pulling my hair out, so any help you can give on this would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果那些不在引号内的名称是您想要从中获取值的变量,则可能应该是:
但正如 Geo 所说,有关实际目的/意图的更多详细信息将有助于
顺便说一句,该构造称为字符串插值(http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#Interpolation)
if those names not inside the quotes are variables that you want to get the values from it should probably be:
but as Geo said, more detail on the actual purpose/intent would help
BTW, that construc tis called string interpolation (http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#Interpolation)
如果您想插入字符串,例如将它们的值包含在字符串中,那么也许这个示例可以帮助您:
在上面的示例中,
c
将具有值:this is a string
。此外,在插值时,会接受有效的 Ruby 代码。所以,这也可以:在这种情况下,
c
将具有值is a string
。因此,如果您需要插入某些内容,请首先考虑如何使用普通代码来执行此操作,然后只需在其周围添加#{}
即可。If you want to interpolate the strings, as in include their value in a string, then maybe this examples can help you:
In the example above,
c
will have the value:this is a string
. Also, while interpolating, valid Ruby code is accepted. So, this is ok too:And in this case,
c
will have the valueis a string
. So, if you need to interpolate something, first think about how you would do it using normal code, and then just add#{}
around it.我想通了。
这是工作代码
看起来我还有很长的路要走.......哈哈
I figured it out.
Here is the working code
Looks like I was a long way off.......lol