我是Ruby的新手。我试图使用方法打印类的类型和名称,但我得到这个语法错误,我无法弄清楚:
Code/oop.rb:47: syntax error, unexpected end-of-input
puts <<TYPE, <<EOF, <<NAME
^
这是我的代码:
def whatClass()
class_type = self.type
class_name = self.name
puts <<TYPE, <<EOF, <<NAME
class_type
TYPE
\n
EOF
class_name
NAME
end
答案 0 :(得分:3)
有多个错误。
序言:name
和puts <<HEREDOC
Heredoc
HEREDOC
不是标准方法。在下面的示例中,我将其替换为字符串。
当您使用Here-Documents时:
HEREDOC
然后结束<<-HEREDOC
必须从第0列开始,并且可能没有尾随空格。如果您有前导空格,则必须以puts <<-HEREDOC
Heredoc
HEREDOC
开头:
def whatClass()
class_type = 'type' #self.type undefined method `type'
class_name = 'name' #self.name
puts <<-TYPE, <<-EOF, <<-NAME
class_type
TYPE
\n
EOF
class_name
NAME
end
所以你的例子是:
TYPE
再次:EOF
,NAME
和NAME
中可能没有尾随空格(当我以剪切+粘贴为例时, class_type
class_name
处有尾随空格)。
下一个错误:
输出
def whatClass()
class_type = 'type' #self.type undefined method `type'
class_name = 'name' #self.name
puts <<-TYPE, <<-EOF, <<-NAME
#{class_type}
TYPE
\n
EOF
#{class_name}
NAME
end
但我认为你想要两个变量的内容。所以我认为你需要:
Exception Thrown: System.IO.FileLoadException: Could not load file or assembly 'SendGrid.SmtpApi, Version=1.1.3.0, Culture=neutral, PublicKeyToken=55aa52d3c3c0d2b2' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'SendGrid.SmtpApi, Version=1.1.3.0, Culture=neutral, PublicKeyToken=55aa52d3c3c0d2b2' at SendGrid.SendGridMessage..ctor() at seshpicker.Controllers.AccountController.<ForgotPassword>d__18.MoveNext() WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
答案 1 :(得分:0)
试试这个:
+(amountBeforeComma + "." + amountAfterComma)