在两种情况下,我没有得到一致的输出:
public void getFitnessData() {
Request request = new Request();
request.setAccess_token("d80fa6bd6f78cc704104d61146c599bc94b82ca225349ee68762fc6c70d2dcf0");
request.setEnd_date("2018-07-01T00:00:00");
Flowable<Response> fitnessFlowable = new WebRequest()
.getRemoteClient()
.create(FitnessApi.class)
.getFitnessData("5b238abb4d3590001d9b94a8",request.toMap());
fitnessFlowable.subscribeOn(Schedulers.io())
.takeUntil(response->response.getSummary().getNext()!=null)
.doOnNext((response) -> {
if(response ==null || response.getFitness() == null || response.getFitness().isEmpty()) {
Log.e(TAG, " Error ");
return;
}
RxBus.getInstance().send(response.getFitness());
try(Realm r = Realm.getDefaultInstance()) {
r.executeTransaction((realm) -> {
realm.copyToRealmOrUpdate(response.getFitness());
});
}
}).subscribe(item ->{
},
error ->{
RxBus.getInstance().error(error);
});
}
humen = {"hand" => 1, "eye" => 2, "head" => 3, "hair"=>4}
puts "enter any body part name"
internal = gets.chomp.downcase.to_s
body = humen[internal]
puts body
#if input is "eye", it comes out 2
我在irb控制台中看不到任何东西。谁能解释为什么会这样吗?
答案 0 :(得分:6)
键在第二种情况下是符号-
{:hand=>1, :eye=>2, :head=>3, :hair=>4}
而internal
是字符串。
humen[internal]
期望分配给internal的字符串出现在哈希humen
中,情况并非如此。
:hand != 'hand'
您应通过以下方式将字符串转换为符号:
humen[internal.to_sym]
String#to_sym
将字符串转换为符号。