- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在阅读“The Well Grounded Rubyist 2nd Edition”
我在第 196 页,并获得了以下代码
class Account
attr_accessor :balance
def initialize(amount=0)
self.balance = amount
end
def +(x)
self.balance += x
end
def -(x)
self.balance -= x
end
def to_s
balance.to_s
end
end
2.3.3 :001 > require './account.rb'
=> true
2.3.3 :002 > acc = Account.new(20)
=> #<Account:0x007fccb1834ef8 @balance=20>
2.3.3 :003 > balance
NameError: undefined local variable or method `balance' for main:Object
from (irb):3
from /Users/BartJudge/.rvm/rubies/ruby-2.3.3/bin/irb:11:in `<main>'
2.3.3 :004 > acc.balance
=> 20
2.3.3 :005 > acc+=5
=> 25
2.3.3 :006 > acc.balance
NoMethodError: undefined method `balance' for 25:Fixnum
from (irb):6
from /Users/BartJudge/.rvm/rubies/ruby-2.3.3/bin/irb:11:in `<main>'
2.3.3 :007 > acc -= 5
=> 20
2.3.3 :008 > acc.balance
NoMethodError: undefined method `balance' for 20:Fixnum
from (irb):8
from /Users/BartJudge/.rvm/rubies/ruby-2.3.3/bin/irb:11:in `<main>'
2.3.3 :009 >
acc.balance
但是,当我在第 8 行再次使用它时,出现以下错误
undefined method `balance' for 20:Fixnum
=> true
2.3.3 :002 > acc = Account.new(20)
=> #<Account:0x007f82d1834f18 @balance=20>
2.3.3 :003 > acc.balance
=> 20
2.3.3 :004 > acc.balance
=> 20
2.3.3 :005 > acc.+ (5)
=> 25
2.3.3 :006 > acc.balance
=> 25
2.3.3 :007 > acc.-(10)
=> 15
2.3.3 :008 > acc.balance
=> 15
2.3.3 :009 >
最佳答案
+=
和 -=
赋值运算符实际上是重新分配变量。 acc += 1
实际上只是 acc = acc + 1
的简写.
And why FIXNUM is getting involved. I thought @balance would be an INTEGER.
关于Ruby 2.3.3 The Well Grounded Rubyist - 未定义方法 `balance' for 25 :Fixnum,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59235910/
我正在尝试填充一个容器或一口井,但我相信容器会更好用。我需要容器保持它在这个 Jsfiddle 中的大小,但我需要将文本放大并拉近边界。 Text 最佳答案 这有点难,但并非不可能。您
我有: 身份服务器 4, 具有 OpenId Connect 和混合流的 Mvc 应用 WebApi 应用 假设用户已经获得带有 id_token 和访问 token 的 cookie。然后他从 mv
我有: 身份服务器 4, 具有 OpenId Connect 和混合流的 Mvc 应用 WebApi 应用 假设用户已经获得带有 id_token 和访问 token 的 cookie。然后他从 mv
这是一个简单的用户登录。我只是想了解这个概念。让我解释一下我的代码问题。这是我的表单: User: Password: check_login.php: Use
我的数据库中有 XML 数据(不是文件)我需要解析它以提供编写测试来验证 xml 中的数据的可能性 xml(内容数据): 250000000032 100104653 NORM M2 0
我正在学习 Java 字节码。我想知道我是否正确理解了这个字节码过程 我还没有完成,但这只是好路的开始.. 00000000 aload_0 // load param1 (String) //
虽然标题说问题是“健康”,但事实是它在表格上随机选择一个项目并说这就是问题。 surveys.views.py from django.shortcuts import render from sur
您好,当涉及到 Bootstrap 时,我对输出有疑问。有时主标题和井输出离开屏幕。每当用户在问题区域中键入内容时,他都会得到响应,并且该响应在移动 View 中会离开屏幕。以及标题 1 文本: He
我在将文本放入 Bootstrap 的背景时遇到问题。我第一次发布问题in this question ,但这是对我的问题的一种过于简单的表述。我正在寻找创建的效果 in this jFiddle ,
我使用展开和折叠而不是下拉菜单构建了一个导航菜单。我的问题是单击菜单链接时无法切换 div。我试过在单击链接时使用 js 将其关闭,但我无法再次打开菜单。 这是我的 html:
如您在此屏幕截图中所见,图像位于 .well 元素之外。在这里你可以看到我的源代码: News mit Bild Geschri
我会尝试使图像与边界线对齐。但我想不通。 (如下图)而且我不确定为什么井没有覆盖我的内容。不知道是什么问题。希望你能帮上忙。 任何帮助将不胜感激! .img-responsive { left
我在页面上延伸了 4 个跨度,我想对前三个应用一口井。这将使井包裹在前 3 个跨度周围,为它们提供背景边距等... 我在第 4 个跨度之前使用了 ended the well div,但它仍然横跨页面
这是网站 link .页脚是 Bootstrap 的 .well。它有一些默认的 margin-bottom 你可以通过 inspect element 选项看到它。现在我已经尝试了我所知道的一切来删
在我的开发环境中,我升级到 rails 4.1.0 并删除了一些旧的 Bootstrap 。现在,我主页上的 bootstrap Wells 不再适用于移动宽度屏幕。 这是我的最后一次提交,目前尚未应
我想构建一个脚本,每分钟检查一次服务器上的 RabbitMQ 实例。是否有可能检查 RabbitMQ 在自动模式下是否“运行良好”,可能是通过脚本(ruby、python 等)或命令行。通过“做得好”
我的主页上有三个 .well 元素,我不想用内容填充它们只是为了确保它们在每个屏幕上的尺寸都正确。理想情况下,我想要一个 CSS 解决方案,它可以指定它们的高度和宽度彼此匹配,而不管它们在哪个屏幕上显
当我尝试在多个网格元素周围环绕一口井时遇到问题。我不确定它是否开箱即用,或者我是否不确定将井类放在哪里。 http://jsfiddle.net/AdamFollett/9xS8Y/1/
我在下面收到此解析错误。我无法让它工作。怎么了? 最佳答案 您经常使用 ”(我认为是 Unicode 字
我正在从我的数据库创建站点地图 XML,它是关于视频站点地图的。在 XML 中,我正在获取视频标题作为 title 和描述作为 description,但有些标题和描述是用泰语、葡萄牙语、德语和其他语
我是一名优秀的程序员,十分优秀!