我正在尝试创建一个方法,将表示字节的整数转换为带有'prettied up'格式的字符串.
这是我的半工作尝试:
class Integer
def to_filesize
{
'B' => 1024,
'KB' => 1024 * 1024,
'MB' => 1024 * 1024 * 1024,
'GB' => 1024 * 1024 * 1024 * 1024,
'TB' => 1024 * 1024 * 1024 * 1024 * 1024
}.each_pair { |e, s| return "#{s / self}#{e}" if self < s }
end
end
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我是Java的新手,需要知道如何将关联数组(Map)作为函数中的单个参数传递.
这是我想用Java做的事情,用PHP表示.
<?php
public class exampleClass {
public function exampleFunction($exampleParam){
if(isset($exampleParam['exampleKey'])){
return true;
}
else {
return false;
}
}
}
$ourMap = array(
'exampleKey' => "yes, it is set"
);
$ourClass = new exampleClass();
$ourResult = $ourClass->exampleFunction($ourMap);
if(!$ourResult){
echo "In Map";
}
else {
echo "Not in Map";
}
?>
Run Code Online (Sandbox Code Playgroud) 我正在计划使用带有Twisted,Storm和Jinja的Python的讨论软件.问题是Jinja不是用于Twisted或异步套接字库,而使用Twisted提供的性能是我不打算使用Flask的原因.
那么,我怎样才能使用Jinja的Twisted渲染网页?