我有两个字符串:
a = 'ha? nô?i'
b = 'hà n?i'
Run Code Online (Sandbox Code Playgroud)
当我与它们进行比较时a == b,它会返回false.
我检查了字节码:
a.bytes = [104, 97, 204, 128, 32, 110, 195, 180, 204, 163, 105]
b.bytes = [104, 195, 160, 32, 110, 225, 187, 153, 105]
Run Code Online (Sandbox Code Playgroud)
原因是什么?我怎样才能修复它以便a == b返回true?
这是我的代码,HTML:
<div id="myApp">
<div class="items">
<div class="item" v-for="quiz in quizzes" :key="quiz.id"}
<span>{{ quiz.question }}</span>
<span v-if="selected[quiz.key]">{{ quiz.answer }}</span>
<a href: "#" v-on:click="quizSelect(quiz.key, $event)">Select</a>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS代码:
new Vue({
el: '#myApp'
data: {
selected: {},
quizzes: [
{
key: 'k1',
question: 'This is question 1',
answer: 'This is answer 1'
},
{
key: 'k2',
question: 'This is question 2',
answer: 'This is answer 2'
}
]
},
methods: {
quizSelect: function(key, e) {
e.preventDefault();
this.selected[key] = 'selected';
}
}
}) …Run Code Online (Sandbox Code Playgroud) 我有两个看起来像这样的数组:
数组1:
Array
(
[0] => name
[1] => age
[2] => job
)
Run Code Online (Sandbox Code Playgroud)
数组2:
Array
(
[0] => name
[1] => toan
[2] => age
[3] => 21
[4] => job
[5] => coder
)
Run Code Online (Sandbox Code Playgroud)
现在,我想从键中获取值0, 2, 4,并使这些值成为自己的键,指向1, 3, 5数组中键的值,如下所示:
Array
(
[name] => toan
[age] => 21
[job] => coder
)
Run Code Online (Sandbox Code Playgroud)
什么是简单快捷的方法呢?
基本上,这是正常的代码:
class Foo
def hi
# your code here....
rescue => e
# Raise error here
end
def hello
# your code here...
rescue => e
# Raise error here
end
end
Run Code Online (Sandbox Code Playgroud)
但在 PHP 中,我可以使用__call魔术方法创建抽象类,如下所示:
class FooAbstract {
public function __call($name, $args) {
# Try catch in here...
}
}
class Foo extends FooAbstract {
public function hi() {
# Code with try catch...
}
}
Run Code Online (Sandbox Code Playgroud)
我如何在 Ruby 类中使用 __call 方法???