idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
10,700
def position_changed ( previous ) add = previous . object ? previous . object . padded_length : 0 next_at = previous . at + add next_pos = Position . get ( @object ) next_pos . set ( next_at ) end
when the argument changes position we update the next objects position to reflect that change
10,701
def resolve_and_add ( slot , compiler ) index = resolve_index ( slot ) new_left = get_new_left ( slot , compiler ) compiler . add_code Risc :: SlotToReg . new ( "SlotLoad #{type}[#{slot}]" , self , index , new_left ) new_left end
using the registers type resolve the slot to an index Using the index and the register add a SlotToReg to the instruction
10,702
def reduce_int reduce = Risc . slot_to_reg ( "int -> fix" , self , Parfait :: Integer . integer_index , self ) builder . add_code ( reduce ) if builder reduce end
reduce integer to fixnum and add instruction if builder is used
10,703
def next_reg_use ( type , extra = { } ) int = @symbol [ 1 , 3 ] . to_i raise "No more registers #{self}" if int > 11 sym = "r#{int + 1}" . to_sym RegisterValue . new ( sym , type , extra ) end
helper method to calculate with register symbols
10,704
def op ( operator , right ) ret = Risc . op ( "operator #{operator}" , operator , self , right ) builder . add_code ( ret ) if builder ret end
create operator instruction for self and add doesn t read quite as smoothly as one would like but better than the compiler version
10,705
def to_mom ( compiler ) raise "Empty list ? #{statements.length}" if empty? stats = @statements . dup first = stats . shift . to_mom ( compiler ) while ( nekst = stats . shift ) first . append nekst . to_mom ( compiler ) end first end
to_mom all the statements . Append subsequent ones to the first and return the first .
10,706
def init_lists ( hash ) self . methods = nil self . names = List . new self . types = List . new raise "No type Type in #{hash}" unless hash [ :type ] private_add_instance_variable ( :type , hash [ :type ] ) hash . each do | name , type | private_add_instance_variable ( name , type ) unless name == :type end end
this part of the init is seperate because at boot time we can not use normal new new is overloaded to grab the type from space and before boot that is not set up
10,707
def add_instance_variable ( name , type ) raise "No nil name" unless name raise "No nil type" unless type hash = to_hash hash [ name ] = type return Type . for_hash ( object_class , hash ) end
add the name of an instance variable Type objects are immutable so a new object is returned As types are also unique two same adds will result in identical results
10,708
def determine_operands if ( @left . is_a? ( Parfait :: Object ) or @left . is_a? ( Risc :: Label ) or ( @left . is_a? ( Symbol ) and ! Risc :: RegisterValue . look_like_reg ( @left ) ) ) left = @left left = left . address if left . is_a? ( Risc :: Label ) right = Risc :: Position . get ( left ) - 8 right -= Risc :: Pos...
don t overwrite instance variables to make assembly repeatable this also loads constants which are issued as pc relative adds
10,709
def installed_template_manifest_patterns builtin_patterns = [ ] config_patterns = [ "#{File.expand_path(opts.config_path)}/*/*.txt" ] current_patterns = [ "*/*.txt" , "node_modules/*/*.txt" , ] patterns = [ ] patterns += current_patterns patterns += config_patterns patterns += builtin_patterns end
shared methods for handling manifest lookups
10,710
def write_as_string @stream = StringIO . new write_init ( @linker . cpu_init ) write_debug write_objects write_code log . debug "Assembled 0x#{stream_position.to_s(16)} bytes" return @stream . string end
objects must be written in same order as positioned by the linker namely - intial jump - all objects - all BinaryCode
10,711
def write_code @linker . assemblers . each do | asm | asm . callable . each_binary do | code | write_any ( code ) end end end
Write the BinaryCode objects of all methods to stream . Really like any other object it s just about the ordering
10,712
def write_any ( obj ) write_any_log ( obj , "Write" ) if stream_position != Position . get ( obj ) . at raise "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not #{Position.get(obj)}" end write_any_out ( obj ) write_any_log ( obj , "Wrote" ) Position . get ( obj ) end
Write any object just logs a bit and passes to write_any_out
10,713
def write_object ( object ) obj_written = write_object_variables ( object ) log . debug "instances=#{object.get_instance_variables.inspect} mem_len=0x#{object.padded_length.to_s(16)}" indexed_written = write_object_indexed ( object ) log . debug "type #{obj_written} , total #{obj_written + indexed_written} (array #{ind...
write type of the instance and the variables that are passed variables ar values ie int or refs . For refs the object needs to save the object first
10,714
def write_ref_for object case object when nil @stream . write_signed_int_32 ( 0 ) when :: Integer @stream . write_signed_int_32 ( object ) else @stream . write_signed_int_32 ( Position . get ( object ) + @linker . platform . loaded_at ) end end
write means we write the resulting address straight into the assembler stream object means the object of which we write the address
10,715
def index_of ( item ) max = self . get_length counter = 0 while ( counter < max ) if ( get ( counter ) == item ) return counter end counter = counter + 1 end return nil end
index of item return nil if no such item
10,716
def next_value ( val ) index = index_of ( val ) return nil unless index return nil if index == ( get_length - 1 ) return get ( index + 1 ) end
return the next of given . Nil if item not in list or there is not next
10,717
def download ( path , options = { } ) path = path . sub ( / \/ / , '' ) rest = Dropbox . check_path ( path ) . split ( '/' ) rest << { :ssl => @ssl } api_body :get , 'files' , root ( options ) , * rest end
Downloads the file at the given path relative to the configured mode s root .
10,718
def delete ( path , options = { } ) path = path . sub ( / \/ / , '' ) path . sub! / \/ / , '' begin api_response ( :post , 'fileops' , 'delete' , :path => Dropbox . check_path ( path ) , :root => root ( options ) , :ssl => @ssl ) rescue UnsuccessfulResponseError => error raise FileNotFoundError . new ( path ) if error ...
Deletes a file or folder at the given path . The path is assumed to be relative to the configured mode s root .
10,719
def rename ( path , new_name , options = { } ) raise ArgumentError , "Names cannot have slashes in them" if new_name . include? ( '/' ) path = path . sub ( / \/ / , '' ) destination = path . split ( '/' ) destination [ destination . size - 1 ] = new_name destination = destination . join ( '/' ) move path , destination ...
Renames a file . Takes the same options and raises the same exceptions as the move method .
10,720
def link ( path , options = { } ) path = path . sub ( / \/ / , '' ) begin rest = Dropbox . check_path ( path ) . split ( '/' ) rest << { :ssl => @ssl } api_response ( :get , 'links' , root ( options ) , * rest ) rescue UnsuccessfulResponseError => error return error . response [ 'Location' ] if error . response . kind_...
Returns a cookie - protected URL that the authorized user can use to view the file at the given path . This URL requires an authorized user .
10,721
def shares ( path , options = { } ) path = path . sub ( / \/ / , '' ) rest = Dropbox . check_path ( path ) . split ( '/' ) begin return JSON . parse ( api_response ( :post , 'shares' , root ( options ) , * rest ) . body ) . symbolize_keys_recursively rescue UnsuccessfulResponseError => error return error . response [ '...
Creates and returns a shareable link to files or folders .
10,722
def metadata ( path , options = { } ) path = path . sub ( / \/ / , '' ) args = [ 'metadata' , root ( options ) ] args += Dropbox . check_path ( path ) . split ( '/' ) args << Hash . new args . last [ :file_limit ] = options [ :limit ] if options [ :limit ] args . last [ :hash ] = options [ :prior_response ] . hash if o...
Returns a + Struct + containing metadata on a given file or folder . The path is assumed to be relative to the configured mode s root .
10,723
def position_changed ( position ) instruction = position . object return unless instruction . is_a? ( Label ) instruction . address . set_value ( position . at ) end
update label positions . All else done in position_changing
10,724
def set ( key , value ) index = key_index ( key ) if ( index ) i_values . set ( index , value ) else i_keys . push ( key ) i_values . push ( value ) end value end
set key with value returns value
10,725
def each index = 0 while index < i_keys . get_length key = i_keys . get ( index ) value = i_values . get ( index ) yield key , value index = index + 1 end self end
yield to each key value pair
10,726
def on_array expression ArrayStatement . new expression . children . collect { | elem | process ( elem ) } end
Array + Hashes
10,727
def on_super ( statement ) arguments = process_all ( statement . children ) SendStatement . new ( nil , SuperExpression . new , arguments ) end
this is a call to super with args and same name as current method which is set later
10,728
def resolve_method ( m_name ) raise "resolve_method #{m_name}.#{m_name.class}" unless m_name . is_a? ( Symbol ) method = get_instance_method ( m_name ) return method if method if ( super_class_name && super_class_name != :Object ) method = self . super_class . resolve_method ( m_name ) end method end
get the method and if not found try superclasses . raise error if not found
10,729
def create_albums ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + '/Albums' ) post ( uri , data , generate_objects ) end
Create Albums .
10,730
def update_albums ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + '/Albums' ) put ( uri , data , generate_objects ) end
Modify Albums .
10,731
def update_categories ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Categories" ) put ( uri , data , generate_objects ) end
Modify system Categories .
10,732
def create_copyright_holders ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/CopyrightHolders" ) post ( uri , data , generate_objects ) end
Create CopyrightHoloders .
10,733
def update_copyright_holders ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/CopyrightHolders" ) put ( uri , data , generate_objects ) end
Modify CopyrightHolders .
10,734
def create_copyright_policies ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/CopyrightPolicies" ) post ( uri , data , generate_objects ) end
Create CopyrightPolicies .
10,735
def update_copyright_policies ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/CopyrightPolicies" ) put ( uri , data , generate_objects ) end
Modify CopyrightPolicies .
10,736
def create_fields ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Fields" ) post ( uri , data , generate_objects ) end
Create fields .
10,737
def update_fields ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Fields" ) put ( uri , data , generate_objects ) end
Modify fields .
10,738
def get_field_lookup_strings ( field = nil , query_obj = nil , with_nested_resources = false , use_http_query = false ) id = Validator . validate_field_lookup_string_arg ( field ) uri = URI . parse ( @uri + "/Fields" + "/#{id}" + "/FieldLookupStrings" ) handle_get_request ( uri , query_obj , with_nested_resources , use...
FIELD LOOKUP STRINGS
10,739
def create_field_lookup_strings ( field = nil , data = nil , generate_objects = false ) id = Validator . validate_field_lookup_string_arg ( field ) uri = URI . parse ( @uri + "/Fields" + "/#{id}" + "/FieldLookupStrings" ) post ( uri , data , generate_objects ) end
creates options for Fixed Suggestion Suggestion and Option field types .
10,740
def update_field_lookup_strings ( field = nil , data = nil , generate_objects = false ) id = Validator . validate_field_lookup_string_arg ( field ) uri = URI . parse ( @uri + "/Fields" + "/#{id}" + "/FieldLookupStrings" ) put ( uri , data , generate_objects ) end
Modifies options for Fixed Suggestion Suggestion and Option field types .
10,741
def upload_file ( file = nil , category = nil , project = nil , generate_objects = false , read_timeout = 600 , low_priority_processing = false ) __upload_file ( file , category , project , generate_objects , read_timeout , low_priority_processing ) end
Uploads a file to OpenAsset .
10,742
def replace_file ( original_file_object = nil , replacement_file_path = '' , retain_original_filename_in_oa = false , generate_objects = false ) __replace_file ( original_file_object , replacement_file_path , retain_original_filename_in_oa , generate_objects ) end
Replace a file in OpenAsset .
10,743
def download_files ( files = nil , image_size = '1' , download_location = './Rest_Downloads' ) files = [ files ] unless files . is_a? ( Array ) files . download ( image_size , download_location ) end
Download Files .
10,744
def update_files ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Files" ) put ( uri , data , generate_objects ) end
Update Files .
10,745
def create_groups ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Groups" ) post ( uri , data , generate_objects ) end
Create Groups .
10,746
def update_groups ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Groups" ) put ( uri , data , generate_objects ) end
Update Groups .
10,747
def create_keywords ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Keywords" ) post ( uri , data , generate_objects ) end
Create new file Keywords in OpenAsset .
10,748
def update_keywords ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Keywords" ) put ( uri , data , generate_objects ) end
Modify file Keywords .
10,749
def merge_keywords ( target , source ) uri = URI . parse ( @uri + "/Keywords" ) merge ( uri , target , source ) end
Merge Keywords .
10,750
def create_keyword_categories ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/KeywordCategories" ) post ( uri , data , generate_objects ) end
Create file keyword categories .
10,751
def update_keyword_categories ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/KeywordCategories" ) put ( uri , data , generate_objects ) end
Modify file keyword categories .
10,752
def merge_keyword_categories ( target , source ) uri = URI . parse ( @uri + "/KeywordCategories" ) merge ( uri , target , source ) end
Merge Keyword Categories .
10,753
def create_photographers ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Photographers" ) post ( uri , data , generate_objects ) end
Create Photographers .
10,754
def update_photographers ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Photographers" ) put ( uri , data , generate_objects ) end
Modify Photographers .
10,755
def create_projects ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Projects" ) post ( uri , data , generate_objects ) end
Create Projects .
10,756
def update_projects ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Projects" ) put ( uri , data , generate_objects ) end
Modify Projects .
10,757
def create_project_keywords ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/ProjectKeywords" ) post ( uri , data , generate_objects ) end
Create Project Keywords .
10,758
def update_project_keywords ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/ProjectKeywords" ) put ( uri , data , generate_objects ) end
Modify Project Keywords .
10,759
def merge_project_keywords ( target , source ) uri = URI . parse ( @uri + "/ProjectKeywords" ) merge ( uri , target , source ) end
Merge Project Keywords
10,760
def create_project_keyword_categories ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/ProjectKeywordCategories" ) post ( uri , data , generate_objects ) end
Create project keyword categories .
10,761
def update_project_keyword_categories ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/ProjectKeywordCategories" ) put ( uri , data , generate_objects ) end
Modify project keyword categories .
10,762
def merge_project_keyword_categories ( target , source ) uri = URI . parse ( @uri + "/ProjectKeywordCategories" ) merge ( uri , target , source ) end
Merge Project Keyword Categories
10,763
def create_employee_keywords ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/EmployeeKeywords" ) post ( uri , data , generate_objects ) end
Create Employee Keywords .
10,764
def update_employee_keywords ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/EmployeeKeywords" ) put ( uri , data , generate_objects ) end
Modify Employee Keywords .
10,765
def merge_employee_keywords ( target , source ) uri = URI . parse ( @uri + "/EmployeeKeywords" ) merge ( uri , target , source ) end
Merge Employee Keywords
10,766
def create_employee_keyword_categories ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/EmployeeKeywordCategories" ) post ( uri , data , generate_objects ) end
Create employee keyword categories .
10,767
def update_employee_keyword_categories ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/EmployeeKeywordCategories" ) put ( uri , data , generate_objects ) end
Modify employee keyword categories .
10,768
def merge_employee_keyword_categories ( target , source ) uri = URI . parse ( @uri + "/EmployeeKeywordCategories" ) merge ( uri , target , source ) end
Merge Employee Keyword Categories
10,769
def create_searches ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Searches" ) post ( uri , data , generate_objects ) end
Create Searches .
10,770
def update_searches ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Searches" ) put ( uri , data , generate_objects ) end
Modify Searches .
10,771
def create_image_sizes ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Sizes" ) post ( uri , data , generate_objects ) end
Create image Sizes .
10,772
def update_image_sizes ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Sizes" ) put ( uri , data , generate_objects ) end
Modify image Sizes .
10,773
def create_users ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Users" ) post ( uri , data , generate_objects ) end
Create Users .
10,774
def update_users ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Users" ) put ( uri , data , generate_objects ) end
Update Users .
10,775
def create_employees ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Employees" ) post ( uri , data , generate_objects ) end
Create employees .
10,776
def update_employees ( data = nil , generate_objects = false ) uri = URI . parse ( @uri + "/Employees" ) put ( uri , data , generate_objects ) end
Update Employees .
10,777
def set_options ( options ) self . port = options [ :port ] . to_i if options . key? ( :port ) self . handler = options [ :handler ] if options . key? ( :handler ) self . host = options [ :host ] if options . key? ( :host ) self . auto_port = options [ :auto_port ] if options . key? ( :auto_port ) end
Sets the options this is a separate method as we want to override certain things set in the rogerfile from the commandline
10,778
def free_port_for_host_above ( host , port ) test_port = port test_port += 1 until port_free? ( host , test_port ) || port + 100 <= test_port test_port end
Get the first free port for host above port Will only ever test 100 ports .
10,779
def port_free? ( host , port ) Addrinfo . tcp ( host , port ) . listen . close true rescue SocketError , Errno :: EADDRINUSE , Errno :: EACCES false end
See if a certain port is free on a certain host
10,780
def detect_valid_handler ( servers ) handler = nil while ( server_name = servers . shift ) && handler . nil? begin handler = :: Rack :: Handler . get ( server_name ) return [ handler , server_name ] rescue LoadError handler = nil rescue NameError handler = nil end end end
See what handlers work
10,781
def render_with_tilt_template ( template_class , src , locals , & _block ) @current_tilt_template = template_class template = template_class . new ( source_path ) { src } block_content = if block_given? yield else "" end template . render ( @context , locals ) do | name | if name @context . _content_for_blocks [ name ]...
Render source with a specific tilt template class
10,782
def extract_front_matter ( source ) fm_regex = / \A \s \n \n \s \n /m return [ { } , source ] unless match = source . match ( fm_regex ) source = source . sub ( fm_regex , "" ) begin data = ( YAML . safe_load ( match [ 1 ] ) || { } ) . inject ( { } ) do | memo , ( k , v ) | memo [ k . to_sym ] = v memo end rescue * YAM...
Get the front matter portion of the file and extract it .
10,783
def use ( processor , options = { } ) @stack << [ self . class . get_callable ( processor , Roger :: Release :: Processors . map ) , options ] end
Use a certain pre - processor
10,784
def run! project . mode = :release validate_paths! copy_source_path_to_build_path! validate_stack! run_stack! cleanup! if config [ :cleanup_build ] ensure project . mode = nil end
Actually perform the release
10,785
def serve server_options = { } options . each { | k , v | server_options [ k . to_sym ] = v } server_options [ :server ] = { } [ :port , :handler , :host ] . each do | k | server_options [ :server ] [ k ] = server_options . delete ( k ) if server_options . key? ( k ) end @project . server . set_options ( server_options...
The handler to use
10,786
def load return unless File . exist? ( @path ) && ! loaded? @source = File . read ( @path ) context = Context . new ( self ) eval @source , context . binding , @path . to_s , 1 @loaded = true end
Actually load the rogerfile
10,787
def render ( path , options = { } , & block ) template , layout = template_and_layout_for_render ( path , options ) template_nesting . push ( template ) @data = { } . update ( @data ) . update ( template . data ) render_result = template . render ( options [ :locals ] || { } , & block ) layout . render do render_result...
The render function
10,788
def render_file ( path , options = { } ) pn = absolute_path_from_current_template ( path ) template = template ( pn . to_s , nil ) template_nesting . push ( template ) template . render ( options [ :locals ] || { } ) ensure template_nesting . pop if template end
Render any file on disk . No magic . Just rendering .
10,789
def layout_for_template ( template , options ) layout_name = if template . data . key? ( :layout ) template . data [ :layout ] else get_default_layout ( template , options ) end return BlankTemplate . new if current_template || ! layout_name template ( layout_name , nil , :layout ) end
Gets the layout for a specific template
10,790
def prevent_recursion! ( template ) return unless template . real_source_path caller_templates = template_nesting . select do | t | t . real_source_path == template . real_source_path end return if caller_templates . length <= MAX_ALLOWED_TEMPLATE_NESTING err = "Recursive render detected for '#{template.source_path}'" ...
Will check the template nesting if we haven t already rendered this path before . If it has we ll throw an argumenteerror
10,791
def template ( path , source , type = :template ) if source template = Template . new ( source , @context , source_path : path ) else template_path = case type when :partial find_partial ( path ) when :layout find_layout ( path ) else path end if template_path && File . exist? ( template_path ) template = Template . op...
Will instantiate a Template or throw an ArgumentError if it could not find the template
10,792
def find_partial ( name ) current_path , current_ext = current_template_path_and_extension local_name = [ File . dirname ( name ) , "_" + File . basename ( name ) ] . join ( "/" ) resolver = Resolver . new ( [ File . dirname ( current_path ) ] + @paths [ :partials ] ) result = resolver . find_template ( local_name , pr...
Find a partial
10,793
def prepare_context ( env ) context = Roger :: Template :: TemplateContext . new ( self , env ) self . class . helpers . each do | mod | context . extend ( mod ) end context end
Will set up a new template context for this renderer
10,794
def run_on_file ( file_path , env = { } ) renderer = Roger :: Renderer . new ( env . dup , partials_path : project . partial_path , layouts_path : project . layouts_path ) renderer . render ( file_path , project . options [ :renderer ] || { } ) end
Runs the template on a single file and return processed source .
10,795
def find_template_path ( name , options = { } ) options = { prefer : "html" , } . update ( options ) path = sanitize_name ( name , options [ :prefer ] ) return Pathname . new ( path ) if File . exist? ( path ) path_extension , path_without_extension = split_path ( path ) template_extensions = template_extensions_for_ou...
Finds the template path for name
10,796
def filter_files ( files , path , path_without_extension , template_extensions ) results = [ ] files . each do | file | match = if file . start_with? ( path ) path else path_without_extension end processable_extensions = file [ ( match . length + 1 ) .. - 1 ] . split ( "." ) next unless ( processable_extensions - templ...
Filter a list of files to see wether or not we can process them . Will take into account that the longest match with path will be the first result .
10,797
def sanitize_name ( name , prefer = nil ) path = name . to_s path += ".#{prefer || 'html'}" unless File . basename ( path ) . include? ( "." ) path end
Check if the name is a directory and append index Append preferred extension or html if it doesn t have one yet
10,798
def build_clone_callback ( callback ) case callback when Proc callback when Symbol -> ( original , clone ) { original . send ( callback , clone ) if original . respond_to? ( callback , true ) } end end
We ensure that the passed callback is actually callable on the object we re cloning . This is needed for associations because deep_cloneable calls the callback for every associated object .
10,799
def realtime_store ( hash , key ) ret = nil r0 = Time . now begin ret = yield ensure r1 = Time . now hash [ key ] = ( hash [ key ] || 0 ) + ( r1 . to_f - r0 . to_f ) end ret end
Stores the elapsed real time used to execute the given block in the given hash for the given key and returns the result from the block . If the hash already has a value for that key the time is accumulated .